Capstone: From Raw Rows to Insight Report
Lesson 5 of 5 · View course roadmap
Learn the idea
Time to run the full pipeline every analyst runs, whatever the tool:
- Parse — split each
"region,amount"row into fields - Clean — convert amounts, quarantine garbage with try/except
- Aggregate — total by region with the dict accumulator
- Report — row count, grand total, top region
Parse → clean → aggregate → report is the same skeleton whether the data is 6 rows in a list or 6 billion in a warehouse; only the tools scale up. Ship this and you've done real analysis — the kind that answers an actual business question.
Where you'll use this
This is the nightly job at thousands of companies: parse yesterday's transactions, skip the garbage, total by region, email the summary. You've written the core of a BI pipeline in ~15 lines.
Common mistakes
- Counting a row as valid before it survives conversion — increment inside the try, after int() succeeds.
- row.split(",") assuming exactly two fields — a stray comma shifts everything; in real work check the field count.
- Reporting totals but not the denominator — '490 revenue' means little without 'from 5 valid rows of 6'.
Pro tip
Structure real pipelines as three functions — parse(rows), aggregate(records), report(totals) — so each stage is testable alone. The csv module then replaces your split(",") for free.
Try it yourself
The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.
Output appears here…
Pass the challenge +45 XP
Analyse rows = ["north,120", "south,95", "north,80", "west,x", "east,150", "south,45"], skipping rows whose amount isn't a number. Print three lines: the number of valid rows, the grand total, and the region with the highest total.
5 490 north
Split each row on ","; int() the amount inside try/except; accumulate totals and count valid rows. Top region: max(totals, key=totals.get).
rows = ["north,120", "south,95", "north,80", "west,x", "east,150", "south,45"]
totals = {}
valid = 0
for row in rows:
region, raw_amount = row.split(",")
try:
amount = int(raw_amount)
except ValueError:
continue
valid += 1
totals[region] = totals.get(region, 0) + amount
print(valid)
print(sum(totals.values()))
print(max(totals, key=totals.get))
Run your code to check it…
Check your understanding
Your notes (saved on this device)
Tip: use ← and → to move between lessons, ⌘K to search everything.