Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 03 / Topic 1 of 6

pandas essentials

pandas gives you the DataFrame: a table with named columns, one row per example. The course's churn table comes from ailab.make_churn() — 2,000 customers, generated locally with a fixed seed.

from ailab import make_churn

df = make_churn()
df[["tenure_months", "churned"]].head(3)     # select columns, first rows
df[df["support_calls"] >= 4]                 # filter rows: 124 customers
df["monthly_charges"].mean()                 # 70.03
df.groupby("contract")["churned"].mean()     # churn rate per contract type

That last line is the workhorse: group by a category, aggregate a number.

contract
month-to-month    0.432
one-year          0.195
two-year          0.070

Month-to-month customers churn six times more than two-year ones — found in one line, before any model.

🧪 Quick quiz

  1. Which pandas call gives the churn rate per contract type?
Show the answer

df.groupby("contract")["churned"].mean() — group by the category, then average the 0/1 label within each group.

Done here? The practice set for Part 3 — 4 exercises with solutions — is on the part page.

Search the guide