Data Analytics · pandas
Why Every Data Analyst Should Learn pandas in 2026
Quick summary — why data analysts should learn pandas
Data analysts should learn pandas in 2026 because it turns manual, error-prone spreadsheet steps into repeatable scripts: cleaning messy exports, joining several files, building pivots and groupby summaries, analysing time series and exporting finished reports to Excel, all of which you can rerun in seconds next week.
In this guide you will learn:
- Cleaning messy data — with pandas.
- Joining files — and checking keys.
- Pivots, groupby — and time series.
- An automated weekly — report template.
- Interview questions — on pandas for analysts.
SECTION 01Cleaning messy exports the same way every time
Most analyst time goes into cleaning: trimming spaces, fixing dates, converting text numbers, handling blanks and removing duplicates. In Excel these steps are often done by hand and differ slightly each time. In pandas, you write them once as a script and rerun it on every new export, which makes results consistent and much faster to produce:
| Problem | Manual Excel approach | pandas approach | Benefit |
|---|---|---|---|
| Extra spaces, mixed case | TRIM and PROPER columns | str.strip().str.title() | Same fix every time |
| Dates in mixed formats | Text to Columns by hand | pd.to_datetime(..., dayfirst=True) | Reliable dates |
| Numbers stored as text | VALUE or retyping | pd.to_numeric(errors='coerce') | Bad values flagged |
| Duplicate rows | Remove Duplicates button | drop_duplicates(subset=...) | Documented rule |
import pandas as pd
def clean_orders(df: pd.DataFrame) -> pd.DataFrame:
df = df.copy()
df.columns = [c.strip().lower().replace(" ", "_") for c in df.columns]
df["city"] = df["city"].str.strip().str.title()
df["order_date"] = pd.to_datetime(df["order_date"], dayfirst=True, errors="coerce")
df["amount"] = pd.to_numeric(df["amount"].astype(str).str.replace(",", ""), errors="coerce")
df = df.drop_duplicates(subset="order_id")
return df
raw = pd.DataFrame({
"Order ID": ["A1", "A2", "A2", "A3"],
"City ": [" noida", "DELHI", "DELHI", "gurugram "],
"Order Date": ["03/01/2026", "04/01/2026", "04/01/2026", "bad"],
"Amount": ["1,200", "850", "850", "640"],
})
print(clean_orders(raw))
import pandas as pd
def quality_report(df: pd.DataFrame) -> pd.DataFrame:
return pd.DataFrame({
"dtype": df.dtypes.astype(str),
"missing": df.isna().sum(),
"missing_%": (df.isna().mean() * 100).round(1),
"unique": df.nunique(),
})
df = pd.DataFrame({"city": ["Noida", None, "Delhi"], "amount": [1200, 850, None]})
print(quality_report(df))
SECTION 02Joining files and checking keys
Analysts often combine data from different sources: orders with customers, sales with targets, or twelve monthly files into one. VLOOKUP and copy-paste work for small files but break easily. pandas merge and concat handle large files, and the validate and indicator options help you catch duplicate keys and unmatched rows before they quietly distort totals:
| Task | pandas tool | Safety option | What it catches |
|---|---|---|---|
| Lookup customer details | merge(how='left') | validate='many_to_one' | Duplicate customer IDs |
| Find unmatched rows | merge(indicator=True) | Check '_merge' column | Orders with no customer |
| Stack monthly files | pd.concat | Check columns match | Missing or renamed columns |
| Compare two lists | merge(how='outer') | indicator=True | Items only in one list |
import pandas as pd
orders = pd.DataFrame({"order_id": [1, 2, 3], "customer_id": [10, 11, 99], "amount": [500, 300, 200]})
customers = pd.DataFrame({"customer_id": [10, 11], "segment": ["Retail", "Corporate"]})
merged = orders.merge(customers, on="customer_id", how="left",
validate="many_to_one", indicator=True)
unmatched = merged[merged["_merge"] == "left_only"]
print(merged.drop(columns="_merge"))
print(f"{len(unmatched)} order(s) without a matching customer:", unmatched["order_id"].tolist())
from pathlib import Path
import pandas as pd
# Create two small sample files so the example runs
Path("monthly").mkdir(exist_ok=True)
pd.DataFrame({"order_id": [1, 2], "amount": [100, 200]}).to_csv("monthly/2026-01.csv", index=False)
pd.DataFrame({"order_id": [3], "amount": [150]}).to_csv("monthly/2026-02.csv", index=False)
frames = []
for f in sorted(Path("monthly").glob("*.csv")):
df = pd.read_csv(f)
df["source_month"] = f.stem
frames.append(df)
allmonths = pd.concat(frames, ignore_index=True)
print(allmonths)
SECTION 03Pivots, groupby and time series
Once data is clean, analysts summarise it: totals by region, averages by product, month-over-month change and running totals. pandas groupby and pivot_table do what Excel pivot tables do, but in code you can rerun, and resample makes time-series summaries by week or month simple. These are the operations interviewers most often ask analysts to write:
| Question | pandas tool | Example | Excel equivalent |
|---|---|---|---|
| Total by group | groupby().sum() | Sales by region | Pivot table |
| Two-way summary | pivot_table() | Region by month | Pivot with rows and columns |
| Monthly totals | resample('MS') | Sales per month | Group dates by month |
| Change over time | pct_change() | Month-over-month growth | Manual formula |
import pandas as pd
df = pd.DataFrame({
"date": pd.to_datetime(["2026-01-05", "2026-01-20", "2026-02-03", "2026-02-15", "2026-03-01"]),
"region": ["North", "South", "North", "South", "North"],
"amount": [1000, 700, 1200, 650, 1300],
})
df["month"] = df["date"].dt.to_period("M").astype(str)
pivot = df.pivot_table(index="region", columns="month", values="amount",
aggfunc="sum", fill_value=0, margins=True, margins_name="Total")
print(pivot)
import pandas as pd
df = pd.DataFrame({
"date": pd.to_datetime(["2026-01-05", "2026-01-20", "2026-02-03", "2026-02-15", "2026-03-01"]),
"amount": [1000, 700, 1200, 650, 1300],
})
monthly = df.set_index("date").resample("MS")["amount"].sum().to_frame()
monthly["mom_%"] = (monthly["amount"].pct_change() * 100).round(1)
monthly["running_total"] = monthly["amount"].cumsum()
print(monthly)
SECTION 04Automated weekly report template
Use these templates to turn a weekly manual report into one script. Start with a report you already produce by hand, so you can compare the script's output with your manual version and build trust before you rely on it.
# pip install pandas openpyxl
import pandas as pd
def build_report(df: pd.DataFrame, path: str = "weekly_report.xlsx") -> None:
df["week"] = df["date"].dt.to_period("W").astype(str)
by_region = df.groupby("region", as_index=False)["amount"].sum()
by_week = df.groupby("week", as_index=False)["amount"].sum()
with pd.ExcelWriter(path) as xl:
by_region.to_excel(xl, sheet_name="By region", index=False)
by_week.to_excel(xl, sheet_name="By week", index=False)
df.to_excel(xl, sheet_name="Data", index=False)
print("saved", path)
sample = pd.DataFrame({
"date": pd.to_datetime(["2026-03-02", "2026-03-04", "2026-03-10"]),
"region": ["North", "South", "North"],
"amount": [500, 300, 450],
})
build_report(sample)
Before sending an automated report:
[ ] Row count matches the source
[ ] No unexpected missing values
[ ] Totals match a manual spot check
[ ] Dates cover the right period
[ ] Sheet names and headers are clear
[ ] Script saved in Git with a short README
Week 1 Series, DataFrames, read_csv, read_excel
Week 2 Cleaning: types, strings, dates, nulls
Week 3 merge, concat, validation checks
Week 4 groupby, pivot_table, resample
Week 5 Export to Excel; automate a real weekly task
Week 6 Portfolio project with README
SECTION 05Tips for data analysts learning pandas
These habits make pandas a daily time-saver rather than another tool you rarely open. They also make your scripts easier for colleagues to read, check and reuse.
- Start with a task you repeat — automate it first for quick wins.
- Check shapes often — print df.shape after each major step.
- Keep raw data untouched — write cleaned output to a new file.
- Spot-check against Excel — build trust in your scripts.
- Learn SQL alongside — the two skills work together.
SECTION 06Interview Q&A — pandas for analysts
Q1How do you handle missing values in pandas?
Find them with isna().sum(), understand why they are missing, then drop, fill or flag them depending on the business meaning.
Q2What is the difference between merge and concat?
merge joins tables side by side on key columns; concat stacks tables on top of each other or side by side by position.
Q3How would you find duplicate records?
Use df.duplicated(subset=[...]) to flag them, inspect a few, then drop_duplicates with a clear rule on which to keep.
Q4How do you create a pivot table in pandas?
Use pivot_table with index, columns, values and aggfunc, optionally with fill_value and margins for totals.
Q5Why might a join increase the number of rows?
Duplicate keys in the right table create multiple matches; use validate and check row counts before and after.
SECTION 07Test yourself — pandas for analysts quiz
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 08Frequently asked questions
Should a data analyst learn pandas or stick to Excel?
Learn both. Excel is great for quick work and sharing; pandas is better for large, messy or repeated tasks that should be scripted.
Is pandas hard to learn for analysts?
With basic Python, most analysts can learn core pandas cleaning, joins and groupby in a few weeks of regular practice on real-style data. Practise on exports similar to the ones you see at work or in listings, because messy real-style files teach more than tidy sample datasets.
Do data analyst job listings ask for pandas?
Many listings mention Python, and pandas is the main Python library for tabular data. Read listings you target to see how often it appears.
Can pandas replace SQL?
No. SQL is used to query databases; pandas is used to process data in Python. Analysts often use SQL to extract and pandas to clean and analyse.
What pandas project should a data analyst build?
Automate a realistic weekly report: clean several messy files, join them, summarise with pivots and export a tidy Excel workbook, with a README. Explain in the README how you checked that the totals match the source, because careful verification is what hiring managers want to see from analysts.
SECTION 09Related reads
Classroom & online · Noida
Master pandas in a data analytics course
Our Data Analytics Training Course covers Excel, SQL, Python, pandas and Power BI, with projects that clean, analyse and report on real-style data.
₹15,500 · full programme- Excel and SQL
- Python and pandas
- Power BI dashboards
- Weekday & weekend batches