

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Aggregation
incomplete
2: Grouping With Dictionaries
incomplete
3: Grouping in Pandas
incomplete
4: Category Type
incomplete
5: Grouping by Multiple Columns
incomplete
6: Multiple Aggregations
incomplete
7: Named Aggregations
incomplete
8: Custom Aggregations
incomplete
9: Pivot Tables
incomplete
10: Pivot Table Aggregations
incomplete
11: Star Schema
incomplete
12: Grain Validation
incomplete
13: Fixing Grain Violations
incomplete
14: Building a Data Model
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
If a column repeats the same small set of labels over and over, plain strings are wasteful. Pandas' category type stores each label once, then uses compact integer codes under the hood. This saves memory and speeds up operations like grouping, sorting, and filtering. It's great for things like:
"free", "pro", "enterprise""West", "Midwest", "Northeast", "South""open", "pending", "closed"You can convert a column to category with astype():
df["region"] = df["region"].astype("category")
If you use groupby() on a category column, observed=True keeps the result focused on categories that actually appear in the data:
df.groupby("region", observed=True)["sales_lead"].count()
Complete the get_region_distribution function. It accepts a DataFrame with fixed region and sales_lead columns, converts the region column to a category type, and returns a DataFrame with one row per observed region and its lead count.