DEV Community

ElvirHajdari
ElvirHajdari

Posted on

How to use the Pandas library in Python

Pandas is a popular Python library for data manipulation and analysis. It is built on top of the NumPy library and provides easy-to-use data structures and data analysis tools for working with numerical, tabular, and time series data.

Here are some examples of how to use the Pandas library in Python:

  • Import the Pandas library:
import pandas as pd
Enter fullscreen mode Exit fullscreen mode
  • Read a CSV file into a Pandas DataFrame:
df = pd.read_csv("data.csv")
Enter fullscreen mode Exit fullscreen mode
  • View the first few rows of the DataFrame:
df.head()
Enter fullscreen mode Exit fullscreen mode
  • Select a column from the DataFrame:
df["column_name"]
Enter fullscreen mode Exit fullscreen mode
  • Filter the DataFrame to only include rows with certain values in a column:
df[df["column_name"] == "value"]
Enter fullscreen mode Exit fullscreen mode
  • Calculate the mean of a column:
df["column_name"].mean()
Enter fullscreen mode Exit fullscreen mode
  • Plot the values in a column using matplotlib:
import matplotlib.pyplot as plt

plt.plot(df["column_name"])
plt.show()
Enter fullscreen mode Exit fullscreen mode

These are just a few examples of how to use Pandas for data manipulation and analysis. For more information, you can refer to the Pandas documentation:

Link

Top comments (0)