Editor

Predict the GroupBy Output

Intermediate · Predict the output · from Pandas GroupBy: Split-Apply-Combine for Powerful Aggregations

From the lesson: Pandas GroupBy: Split-Apply-Combine for Powerful Aggregations

Imagine you have a giant pile of receipts from a store. You want to know how much each department earned last month. What do you do? You sort the receipts into piles by department, add up each pile, and write down the totals.

Read the lesson

What will this code print? Think about how many rows each group has.

import pandas as pd
df = pd.DataFrame({'team': ['A', 'B', 'A', 'B', 'A'], 'score': [10, 20, 30, 40, 50]})
print(df.groupby('team')['score'].count().tolist())
# Type the exact output

More Pandas GroupBy exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz