0Pricing
Data Science Academy · Lesson

Split-Apply-Combine Explained

The model behind every groupby.

Split-Apply-Combine Explained is a free Data Science Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

One Idea, Three Steps

Every groupby follows one rhythm: split the rows into groups, apply a calculation to each, then combine the answers back together. 🔁

Split: Cut by a Key

The split step partitions rows by a key column, so all rows sharing the same value land in the same little group.

groups = df.groupby("city")

Apply: Do Work Per Group

In the apply step, the same function runs on each group on its own, never mixing one group with another.

df.groupby("city")["sales"].mean()

Combine: Stitch Results

The combine step glues each group result into one tidy output, indexed by the group keys you split on.

groupby Is Lazy

Calling groupby alone does almost nothing; it just remembers the plan. The real work waits until you add an aggregation.

g = df.groupby("city")  # no math yet

The Group Key Becomes the Index

After aggregating, your group key moves into the result index, so each unique value labels one output row.

Pick a Column to Aggregate

Select a column after grouping to focus the math. Here you ask for the average sales within each city.

df.groupby("city")["sales"].mean()

size Counts Rows Per Group

Use size when you just want how many rows fell into each group, including any missing values.

df.groupby("city").size()

Iterating Over Groups

You can loop a groupby to inspect it: each turn hands you the group name and the matching sub-table.

for name, part in df.groupby("city"):
    print(name, len(part))

Why It Beats Manual Loops

Split-apply-combine replaces slow hand-written loops with one fast, readable line that pandas optimizes for you. ⚡

A Tiny End-to-End Example

This single line splits by region, averages each group, and combines the result, all in one readable expression.

df.groupby("region")["revenue"].mean()

Quick Check

Which step actually does the calculation?

Recap: The groupby Rhythm

You learned the heartbeat of grouping: split, apply, combine. Master this rhythm and every aggregation later feels natural. 🎯

Frequently asked questions

Is the “Split-Apply-Combine Explained” lesson free?

Yes — the full text of “Split-Apply-Combine Explained” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “Split-Apply-Combine Explained”?

The model behind every groupby. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Split-Apply-Combine Explained” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Split-Apply-Combine Explained
  2. Multiple Aggregations With agg
  3. Group by Several Keys
  4. transform for Group-Wise Features
← Back to Data Science Academy