# Grouping

Grouping: Grouping with groupby, Several Summaries at Once: agg, Shares and Percentages of a Total.

Updated: November 19, 2026

1. [Grouping with groupby](https://www.ask-codey.com/lessons/pandas-groupby) (Apprentice): groupby sorts a table's rows into groups that share a value, such as a neighborhood, works out one number for each group (a sum, a mean, a count) and hands back one row per group, which answers "which one sold the most?" in a line instead of a filter for every group.
2. [Several Summaries at Once: agg](https://www.ask-codey.com/lessons/pandas-groupby-agg) (Journeyman): agg works out several summaries for each group in one table, from a list such as \['sum', 'mean', 'count'\] or by named aggregation, which names each new column and the column and summary it comes from; groupby takes a list of columns to group by two things at once, and reset_index or as_index=False turns the group labels back into ordinary columns.
3. [Shares and Percentages of a Total](https://www.ask-codey.com/lessons/pandas-shares-of-a-total) (Journeyman): A group's total means more beside the whole, so divide each group's total by the grand total and multiply by 100 for its share as a percentage; transform('sum') lines each group's total up with every row, so each row's share of its own group is one division; and shares are rounded to one decimal place only at the end, for people to read.

Source: https://www.ask-codey.com/courses/python-data-analysis/topics/data-grouping
