Learn the Pandas workflow that appears in real analytical work: load, inspect, select, clean, transform, aggregate, merge, work with dates, and publish a controlled result.
Complete 12 of 24 practices (50%) and enter your name to unlock the Certificate of Participation.
Pandas is Python’s workhorse for labeled, tabular data. Its two core structures — Series and DataFrame — let you organize rows and columns with labels, mix data types, and perform analysis using readable table operations.
Think of a DataFrame as an analytical table with memory: columns have names, rows have an index, and operations usually preserve those labels.
import pandas as pd
data = {
"Department": ["Police", "Fire", "Parks"],
"Requests": [420, 315, 188]
}
df = pd.DataFrame(data)
print(df)
print(df["Requests"].mean())Use Pandas when your problem looks like a spreadsheet, database result, CSV, or reporting table. If the work is mostly dense numerical matrix math, NumPy is usually the lower-level tool.
A strong Pandas workflow begins with inspection. Before cleaning or calculating, verify columns, shape, data types, missing values, and a small sample of the rows.
Do not start by “fixing” the file. First ask: What arrived? How many rows? Which columns? Which types? What looks suspicious?
import pandas as pd
df = pd.read_csv("service_requests.csv")
print(df.head())
print(df.shape)
print(df.columns)
print(df.dtypes)
df.info()Inspection is a control step, not a formality. A wrong delimiter, unexpected header, or numeric column loaded as text can invalidate every downstream calculation.
Pandas becomes useful when you can express a business question as a row-and-column selection: which records, which fields, and in what order?
Turn “show me open high-priority requests for District 3” into a Boolean condition plus a short column selection.
high_priority = df.loc[
(df["District"] == 3) &
(df["Status"] == "Open") &
(df["Priority"] == "High"),
["RequestID", "Department", "DaysOpen"]
]
high_priority = high_priority.sort_values("DaysOpen", ascending=False)
print(high_priority.head(10))Use parentheses around each Boolean condition and combine them with & for AND or | for OR. In Pandas, Python’s and/or operators are not the same thing as element-wise table filtering.
Real data is rarely analysis-ready. Pandas gives you a practical cleaning toolkit for missing values, inconsistent text, duplicated rows, and columns stored with the wrong dtype.
Cleaning is not “make everything nonblank.” It is deciding what each field means, what counts as invalid, and how that decision affects the analysis.
df["Employee"] = df["Employee"].str.strip()
df["Amount"] = pd.to_numeric(df["Amount"], errors="coerce")
df = df.drop_duplicates(subset=["TransactionID"])
df["Department"] = df["Department"].fillna("Unknown")
print(df.isna().sum())Never fill, drop, or coerce blindly. A missing salary, missing ZIP code, and missing completion date mean different things. Cleaning rules should follow the field’s business meaning.
Analytical tables become valuable when raw fields are turned into business measures, flags, categories, and standardized values. Pandas supports vectorized column operations that are usually clearer than manual row loops.
If the rule can be described as “for this entire column, calculate…”, try a vectorized expression first.
rate_map = {"A": 1.00, "B": 0.90, "C": 0.80}
df["NetAmount"] = df["Amount"] - df["Discount"]
df["RateFactor"] = df["Rating"].map(rate_map)
df["Adjusted"] = df["NetAmount"] * df["RateFactor"]
df["NeedsReview"] = df["Adjusted"] > 5000
print(df[["NetAmount", "Adjusted", "NeedsReview"]].head())Prefer readable vectorized rules. Use apply() when you truly need custom row/column logic, but do not reach for it automatically when a direct Pandas operation already expresses the rule.
Most reporting questions ask for a summary by something: department, month, category, instructor, branch, product, or customer. groupby() is one of the most important Pandas patterns for turning transaction-level rows into KPIs.
Think “Split → Apply → Combine”: split rows into groups, apply an aggregation, then combine the results into a summary table.
kpi = (
df.groupby("Department", as_index=False)
.agg(
Requests=("RequestID", "count"),
AvgDays=("DaysOpen", "mean"),
TotalCost=("Cost", "sum")
)
.sort_values("Requests", ascending=False)
)
print(kpi)Choose aggregations that match the KPI definition. count, nunique, sum, mean, median, min, and max answer different business questions — they are not interchangeable.
Business data rarely lives in one table. Pandas merge() lets you combine datasets through keys using relational ideas similar to SQL joins.
The question is not only “how do I join?” It is “what should one row represent before and after the join, and can the key multiply rows?”
employees = pd.read_excel("employees.xlsx")
departments = pd.read_excel("departments.xlsx")
result = employees.merge(
departments,
on="DepartmentID",
how="left",
validate="many_to_one"
)
print(result.shape)
print(result.head())Always validate row counts and key uniqueness around a merge. A join can be syntactically correct and still duplicate rows because the key relationship was misunderstood.
Dates are where many real reports become analytical. Convert text to datetime, derive month or weekday features, measure durations, then combine filtering, grouping, and exporting into one repeatable workflow.
Instead of manually creating a monthly report, build a pipeline that can rerun next week with a new file and produce the same logic consistently.
df["Created"] = pd.to_datetime(df["Created"], errors="coerce")
df["Closed"] = pd.to_datetime(df["Closed"], errors="coerce")
df["DaysToClose"] = (df["Closed"] - df["Created"]).dt.days
df["Month"] = df["Created"].dt.to_period("M").astype(str)
monthly = (
df.groupby(["Month", "Department"], as_index=False)
.agg(Closed=("RequestID", "count"),
AvgDays=("DaysToClose", "mean"))
)
monthly.to_excel("monthly_service_kpis.xlsx", index=False)A good production-minded notebook or script separates inputs, validation, transformation, KPI logic, and outputs. That structure makes the analysis easier to audit, rerun, and eventually automate.
Open each item only after answering it in your own words.
A Series is one-dimensional and labeled; a DataFrame is a two-dimensional labeled table.
Because numbers or dates loaded as text can break downstream logic.
It summarizes measures by one or more grouping keys.
Repeated keys can silently multiply rows and alter totals.
Clear inputs, validation, transformation logic, KPI definitions, and controlled outputs.
| Need | Pandas | NumPy | SQL |
|---|---|---|---|
| Clean and reshape mixed-type labeled tables | Excellent | Limited | Good |
| Dense numerical arrays and matrix operations | Good | Excellent | Limited |
| Filter, group and join very large data at the database | Good after extraction | Not primary | Excellent |
| Fast exploratory workflow in Python | Excellent | Good | Good |
| Feed cleaned features into Python models | Excellent | Excellent | Preparation layer |
The technical concepts in this training follow the official Pandas user guide and getting-started tutorials.
“I can load and inspect business datasets with Pandas, select and filter records, clean missing values and types, create calculated fields, summarize KPIs with groupby, combine tables safely with merge, work with dates, and export a controlled result.”
Complete at least 12 of the 24 practice cases (50%) and enter your name.