Files
Tirsvad 1d06a2c892 Add notebook, step screenshots, README screenshots and three-language wiki
Closes #18
Closes #19
Closes #20
Closes #21
Closes #22
Closes #23
Closes #24
Refs #25

Task: MIL-003#1
2026-11-12 08:45:20 +08:00

20 lines
1003 B
Markdown

**English** · [Dansk](Step-4-Themes-per-Year-da) · [Bahasa Malaysia](Step-4-Themes-per-Year-ms)
# Step 4: Themes per year with .agg()
**Question:** How many different themes did LEGO sell each year?
![Step 4: Themes per year with .agg()](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/074-Lego_Analysis_for_Course/raw/branch/main/docs/images/step-4-themes-per-year.png)
## What the code does
`themes_by_year` runs `sets.groupby("year").agg({"theme_id": pd.Series.nunique})` and renames the column to `nr_themes`. There were 2 themes in 1949 and 78 in 2019; `themes_by_year_chart` plots the full calendar years only.
## What you gained
- `.agg()` takes a dictionary: the key is the column, the value is the operation.
- `.rename(columns=...)` gives a column a better name.
- The number of themes grew until the mid-1990s, stalled, and grew again in the early 2010s.
Previous: [Step-3-Sets-per-Year](Step-3-Sets-per-Year) · Next: [Step-5-Two-Axes](Step-5-Two-Axes)