Pandas has hundreds of functions, and beginners often feel they must learn all of them. You do not. A small set of operations covers most day-to-day analysis. Learn these well and look up the rest when you need it.
All examples use a fictional food delivery company, Thali Now, with an orders table: order_id, city, restaurant, order_time, amount, delivery_mins, customer_id.
1. Load and take a first look
import pandas as pd
orders = pd.read_csv("orders.csv", parse_dates=["order_time"])
orders.shape # (rows, columns)
orders.head() # first five rows
orders.info() # column types and non-null counts
orders.describe() # quick stats for numeric columnsinfo() is the most useful of these. It tells you which columns have missing values and whether a column you expected to be a number was read as text.
2. Select columns and filter rows
orders[["city", "amount"]] # columns
orders[orders["amount"] > 500] # rows matching a condition
orders[(orders["city"] == "Pune") & (orders["delivery_mins"] > 45)]
orders.query("city == 'Pune' and delivery_mins > 45") # same thing, easier to readUse & and |, not and / or, and wrap each condition in brackets. Forgetting the brackets is the most common pandas error beginners hit.
3. Count values
orders["city"].value_counts()
orders["city"].value_counts(normalize=True) # shares instead of counts
orders["customer_id"].nunique() # unique customers4. Add and change columns
orders["is_late"] = orders["delivery_mins"] > 40
orders["order_hour"] = orders["order_time"].dt.hour
orders["amount_band"] = pd.cut(orders["amount"], bins=[0, 200, 500, 10_000],
labels=["small", "medium", "large"])5. Group and summarise
This is the pandas version of SQL's GROUP BY, and you will use it constantly.
(orders
.groupby("city")
.agg(orders=("order_id", "count"),
revenue=("amount", "sum"),
late_rate=("is_late", "mean"))
.sort_values("revenue", ascending=False))Named aggregation (new_name=("column", "function")) gives clean column names, which matters when you hand the result to someone else. Note the trick in late_rate: the mean of a True/False column is the share of True values.
6. Merge tables
restaurants = pd.read_csv("restaurants.csv")
df = orders.merge(restaurants, on="restaurant", how="left", validate="many_to_one")how="left" keeps every order, like a SQL LEFT JOIN. The validate argument is underused: it raises an error if the restaurants table has duplicate keys, which would otherwise silently multiply your orders.
7. Pivot for reports
pd.pivot_table(orders, index="city", columns="order_hour",
values="order_id", aggfunc="count", fill_value=0)A pivot table turns a long table into a grid, which is often exactly what a manager wants to see.
8. Handle missing values and duplicates
orders.isna().sum() # missing per column
orders["delivery_mins"] = orders["delivery_mins"].fillna(orders["delivery_mins"].median())
orders = orders.drop_duplicates(subset="order_id")Do not fill missing values automatically. First ask why they are missing. A missing delivery time might mean the order was cancelled, and filling it with the median would hide that.
9. Work with dates
daily = orders.set_index("order_time").resample("D")["amount"].sum()
weekly_avg = daily.rolling(7).mean()
orders["month"] = orders["order_time"].dt.to_period("M")resample groups by time periods; rolling gives moving averages that smooth out daily noise.
10. Save the result
summary.to_csv("city_summary.csv", index=False)How to actually get good at pandas
Read less, write more. Pick a question, write the code, check the answer. Our pandas track goes from a first look at a dataset through groupby, merges and cleaning to full analysis tasks, and runs entirely in your browser. When you are ready to show the results, learn to choose the right chart.
Practise what you just read
Reading helps; writing the code yourself is what sticks. Start here: