Block 27: GroupBy & Aggregations
Summarize data by category using groupby.
Concepts
- df.groupby('col').agg()
- Multiple aggregation functions: mean, sum, count, std
- groupby with multiple columns
- reset_index() after groupby
Code Examples
See exercise below.
Exercise
Using the tips dataset (seaborn), compute average tip by day and by smoker status. Find the top 3 days by total bill amount.
Homework
Compare groupby().mean() with a manual loop approach — what are the advantages?