The single most useful pattern in tabular analytics
The split-apply-combine idiom — split rows into groups, apply a function to each group, combine the per-group results into a final table — covers the vast majority of real-world tabular questions. Pandas exposes it as df.groupby(...), and learning it well is one of the highest-leverage things you can do as a Pandas user.
The three flavors of "apply"
- Aggregate — produce one value per group (sum, mean, median, count). Result has one row per group.
- Transform — produce one value per row, computed within the group (z-score within each store, rank within each customer). Result has the same shape as the input.
- Filter — keep or drop entire groups based on a per-group test ("only stores with >100 orders this month").
Named aggregations are the modern style
Old code uses dictionaries-of-lists (.agg({'amount': ['sum', 'mean']})) and produces ugly multi-index columns. New code uses the named aggregation form: .agg(revenue=('amount_usd', 'sum'), orders=('order_id', 'nunique')). Result columns get clear names, and the code reads as a contract with the consumer.