Split-Apply-Combine

noun

say it: “SPLIT uh-PLY kum-BYNE” /ˈsplɪt əˈplaɪ kəmˈbaɪn/

The three steps of a grouping: split the rows into groups, work out one answer for each group, and combine the answers into one table.

What is split-apply-combine?

Split-apply-combine is what a grouping does in three steps: split the rows into groups that share a value, apply a summary to each group (a sum, a mean, a count), and combine the answers into one result with a row for each group. pandas' groupby() does all three in one line.

import pandas as pd
orders = pd.DataFrame({"neighborhood": ["Elm Park", "Riverside", "Elm Park"], "total": [18.0, 25.0, 22.0]})
print(orders.groupby("neighborhood")["total"].sum())
# neighborhood
# Elm Park     40.0
# Riverside    25.0

In a sentence

  • “Total sales by neighborhood is split-apply-combine in one line.”
  • “She drew split-apply-combine as three boxes: piles of rows, a sum for each pile, one table of sums.”

Level: Journeyman · More Python terms at this level

Updated