DEV Community

Arhan Khan
Arhan Khan

Posted on

Pandas for Beginners: Data Analysis in Python Without the Headaches

If you work with data in Python, you will meet Pandas — the library that turns messy spreadsheets and CSV files into something you can actually analyze. Its core object is the DataFrame: a table with named columns that you can filter, sort, group, and summarize in a few lines.

Start with a CSV file:

import pandas as pd

df = pd.read_csv("sales.csv")

print(df.head())        # first 5 rows
print(df.describe())    # summary stats for numeric columns
print(df.shape)         # (rows, columns)
Enter fullscreen mode Exit fullscreen mode

Filtering is where it starts to feel like magic:

# All orders over 1000 rupees from Mumbai
big_mumbai = df[(df["amount"] > 1000) & (df["city"] == "Mumbai")]

# Total sales per city, sorted
print(df.groupby("city")["amount"].sum().sort_values(ascending=False))

# Monthly average, if you have a date column
df["month"] = pd.to_datetime(df["date"]).dt.to_period("M")
print(df.groupby("month")["amount"].mean())
Enter fullscreen mode Exit fullscreen mode

A few things that trip up beginners: Pandas is happiest when you use its built-in methods instead of Python loops — a groupby is hundreds of times faster than looping over rows. Missing values show up as NaN, and methods like fillna() and dropna() handle them. And dates should be converted with pd.to_datetime() before you do any time math.

Pandas pairs naturally with Matplotlib for charts and Jupyter notebooks for exploration, and it is the first step toward machine learning with scikit-learn.

Pandas is for anyone who analyzes data in Python — students, analysts, and developers who are tired of wrestling with raw CSV files. If you are still learning Python itself, the Python section on Skill Library is a good place to build the foundation first.

Top comments (0)