Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

Capstone: From Raw Rows to Insight Report

18 min 45 XP
Study loop Read Predict Run Tweak Prove Review
Lesson 5 of 5 · View course roadmap
Step 1

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.

Step 2

Try it yourself

Blank · autosaved

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”.

PYexample.py
⌘ + Enter to run
Output appears here…
Step 3

Pass the challenge +45 XP

Blank · autosaved

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.

Target output
5
490
north
PYchallenge.py
Run your code to check it…
Step 4

Check your understanding

1. Put the analysis pipeline in order:
2. Why 'continue' on a bad row instead of letting it crash?
Last step

Your notes (saved on this device)

Tip: use ← and → to move between lessons, ⌘K to search everything.

Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path