Overview
Build a per-customer summary (number of orders, total and average spend) in one groupby with named aggregations.
- .agg(name=(column, function))
- Several statistics at once
- count skips NaN, size doesn't
Short Course
.agg() computes several named statistics per group, like
total=("amount", "sum"). Trap: "count" skips missing values, while
"size" counts every row.
orders.groupby("customer").agg(
orders=("amount", "size"),
total=("amount", "sum"),
)
Task
Write customer_summary(df) that groups by customer and returns the columns
orders (number of rows), total (sum of amount) and average (mean of
amount, rounded to 2 decimals), for example Ana's [10, 20, 15.5] give
3, 45.5 and 15.17.
Test Suites
Pending
Next
Output