Split-Apply-Combine spiegato
Il modello alla base di ogni groupby.
Split-Apply-Combine spiegato è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 1 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Data Science Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Data Science Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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 yetThe 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. 🎯
Domande Frequenti
La lezione «Split-Apply-Combine spiegato» è gratuita?
Sì — il testo completo di «Split-Apply-Combine spiegato» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Data Science Academy, passa a CoddyKit PRO. Il corso Data Science Academy include 4 lezioni in totale.
Cosa imparerò in «Split-Apply-Combine spiegato»?
Il modello alla base di ogni groupby. Eserciti Data Science Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Data Science Academy?
Non è richiesta alcuna esperienza precedente. Data Science Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 1 di 4.
Quanto tempo richiede la lezione «Split-Apply-Combine spiegato»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Data Science Academy?
Sì. Ogni lezione Data Science Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Split-Apply-Combine spiegato
- Aggregazioni multiple con agg
- Raggruppare per più chiavi
- transform per feature a livello di gruppo