---
source: https://iinventedlight.com/library/notes/pandas-groupby.md
title: "pandas groupby: split-apply-combine"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_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); prose restates or closely paraphrases cited source lines"
license_family: pandas-bsd3
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: pandas"
tags: ['pandas', 'groupby', 'aggregation']
sources:
  - id: S1
    title: "Group by: split-apply-combine — pandas 3.1.1 documentation"
    publisher: pandas docs
    url: https://pandas.pydata.org/docs/user_guide/groupby.html
    accessed: 2026-11-04
    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)"
  - id: S2
    title: "How to calculate summary statistics — pandas 3.1.1 documentation"
    publisher: pandas docs
    url: https://pandas.pydata.org/docs/getting_started/intro_tutorials/06_calculate_statistics.html
    accessed: 2026-11-04
    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)"
---
# 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).
