pandas groupby: split-apply-combine
Answer: A group by operation in pandas involves splitting the data into groups based on some criteria, applying a function to each group, and combining the results. Out of these, the split step is the most straightforward. (S1) The apply and combine steps are typically done together in pandas. (S2)
What you can do per group
- Aggregation: compute a summary statistic (or statistics) for each group. (S1)
- Transformation: perform some group-specific computations and return a like-indexed object, such as filling NAs within groups with a value derived from each group. (S1)
- Filtration: discard some groups, according to a group-wise computation that evaluates to True or False. (S1)
- Filtration examples include discarding data that belong to groups with only a few members, or filtering out data based on the group sum or mean. (S1)
In practice
- The groupby() method can be applied to a column to make a group per category. (S2)
- Grouping can be done by multiple columns at the same time: provide the column names as a list to the groupby() method. (S2)
- The aggregating statistic can be calculated for multiple columns at the same time. (S2)
- Both size and count can be used in combination with groupby. (S2)
Claims
- id: C1 claim: Splitting the data into groups is the first step. source: S1 evidence: "Splitting the data into groups based on some criteria."
- id: C2 claim: Aggregation computes a statistic per group. source: S1 evidence: "compute a summary statistic (or statistics) for each"
- id: C3 claim: Apply and combine are usually done together. source: S2 evidence: "The apply and combine steps are typically done together in pandas."
- id: C4 claim: Pass a list of columns to group by several. source: S2 evidence: "column names as a list to the groupby() method."
Sources
- [S1] Group by: split-apply-combine — pandas 3.1.1 documentation. pandas docs. https://pandas.pydata.org/docs/user_guide/groupby.html . License: BSD-3-Clause (pandas-dev/pandas LICENSE; Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team; Copyright (c) 2011-2026, Open source contributors; https://github.com/pandas-dev/pandas/blob/main/LICENSE). Accessed 2026-11-04.
- [S2] How to calculate summary statistics — pandas 3.1.1 documentation. pandas docs. https://pandas.pydata.org/docs/getting_started/intro_tutorials/06_calculate_statistics.html . License: BSD-3-Clause (pandas-dev/pandas LICENSE; Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team; Copyright (c) 2011-2026, Open source contributors; https://github.com/pandas-dev/pandas/blob/main/LICENSE). Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: pandas docs, Group by: split-apply-combine — pandas 3.1.1 documentation, BSD-3-Clause (pandas-dev/pandas LICENSE; Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team; Copyright (c) 2011-2026, Open source contributors; https://github.com/pandas-dev/pandas/blob/main/LICENSE); pandas docs, How to calculate summary statistics — pandas 3.1.1 documentation, BSD-3-Clause (pandas-dev/pandas LICENSE; Copyright (c) 2008-2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team; Copyright (c) 2011-2026, Open source contributors; https://github.com/pandas-dev/pandas/blob/main/LICENSE).
Cite this
iinventedlight. 2026. "pandas groupby: split-apply-combine." iinventedlight Library, iil:note:sdrk92mw, version of 2026-11-04. https://iinventedlight.com/library/notes/pandas-groupby/. License: CC-BY-4.0.
@misc{iil_note_sdrk92mw,
author = {{iinventedlight}},
title = {{pandas groupby: split-apply-combine}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/pandas-groupby/},
note = {Permanent ID iil:note:sdrk92mw. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/pandas-groupby.md.