🚀 074 LEGO Analysis for Course
Day 74 of Udemy's 100 Days of Code: The Complete Python Pro Bootcamp: aggregate and merge data in Pandas while analysing a dataset of LEGO sets. It is for course participants who want runnable, tested code and for anyone browsing for ideas.
📚 Table of Contents
🧭 Overview
The project answers five questions about LEGO: the largest set ever made, the year of the first sets, the theme with most sets, how the product range grew each year, and whether sets got bigger over time.
| Folder | What it holds |
|---|---|
src/lego_analysis/ |
The analysis functions, named as in the assignment |
tests/ |
Tests that assert every value from the lecture |
notebooks/ |
The Jupyter notebook that follows the lecture step by step |
data/ |
colors.csv, sets.csv and themes.csv from the lecture (a 2020 snapshot of the Rebrickable database) |
notebooks/assets/ |
Images supplied with the lecture, next to the notebook that shows them |
docs/ |
Project documents, screenshots (docs/images/) and the wiki sources (docs/wiki/: English, Danish, Bahasa Malaysia) |
scripts/ |
scan.sh (opengrep) and make_screenshots.py |
framework/ |
The SQA and QC framework (a git submodule) that the project documents follow |
.editorconfig |
The editor settings of the framework baseline |
.env.example |
Placeholders for the git host tokens that the framework scripts read; the program itself reads no setting from .env |
🖼️ Lecture steps
One screenshot per lecture step, generated from the code with python scripts/make_screenshots.py. The wiki (English, Dansk, Bahasa Malaysia) explains what each step teaches.
Step 1: Exploring the brick colours
Step 2: The oldest and the largest sets
Step 3: Sets released per year
Step 4: Themes per year with .agg()
Step 5: Two axes in one chart
Step 6: Average parts per set
Step 7: Themes, primary keys and foreign keys
Step 8: Merging DataFrames on a key
Step 9: A bar chart of the top 10 themes
📋 Requirements
- Python 3.13 or newer, to run the code.
pandasandmatplotlib, the only runtime dependencies; they are installed by the setup below.pytest,ruffand Jupyter, only for development; installed with thedevextra.
🛠️ Setup
Create and use a local virtual environment named .venv.
Windows (PowerShell):
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
Linux and macOS:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
Leave out [dev] if you only want to run the analysis.
▶️ Run
Print the answers to the five questions:
python -m lego_analysis
Open the notebook:
jupyter lab notebooks/Lego_Analysis_for_Course.ipynb
🧪 Tests
python -m pytest
python -m mypy
python -m mypy runs the strict type check configured in pyproject.toml on src and tests.
Before pushing, scan the code with opengrep (default path ~/.opengrep/cli/latest/opengrep.exe):
bash scripts/scan.sh
📄 License
GNU Affero General Public License v3.0 only (AGPL-3.0-only), see LICENSE.
🔗 Links
📎 Appendix: Project documents
The documents a newcomer needs, in reading order.
| Document | What it tells you |
|---|---|
| Business Case | Why the project exists, its scope and success criteria |
| Stakeholder Analysis | Who is involved; the stakeholder IDs used for owners and reviewers |
| Project Plan | The gateways and their schedule |
| Milestones | One document per gateway: Go/No-Go criteria and tasks |
| Artifact registry | Where each artifact type lives, the next version, the PO language and domain |
| Wiki sources | The lecture steps explained in English, Danish and Bahasa Malaysia |
| Traceability matrix | How the artifacts link and when each was last reviewed |








