Python for AI
Beginner
4.5

Pandas GroupBy and Aggregation

Summarize data the way you would in SQL, in one line.

0h 25m
1 lesson
1.2K students

What You'll Learn

Learning objectives will be added soon.

Tutorial Content

Split–apply–combine

groupby splits rows into groups, applies a function to each, and combines the results.

# average order value per customer
df.groupby("customer_id")["amount"].mean()

# multiple aggregations at once
df.groupby("category").agg(
    total=("amount", "sum"),
    orders=("amount", "count"),
    avg=("amount", "mean"),
)

Why it matters for ML

Aggregations are how you build features: counts, averages, and recency per entity often predict more than raw rows. Master groupby and you can engineer most tabular features quickly.

Your Progress

Sign in to track your progress

Tags

Python
Data Science
Beginner