Feed to Figure: clean the feed, then report the number it was hiding
This is a Challenge, not a tutorial. There’s no guided walkthrough — just a realistic mess, a question, and a test that tells you when you’ve nailed it. You bring the approach. You don’t need to have done any course here first; if the assumed skills below sound doable, dive in.
The situation
Finance quotes completed net revenue off last month’s orders_feed.csv and it looks low.
You’ve been handed the raw daily feed and a regions.csv lookup, and asked for the real
number — plus an explanation of why the quick read was wrong.
The feed is the kind of thing that actually lands in an inbox:
- the same order sometimes appears twice (an earlier attempt and the final row, same
order_id), - amounts are text —
"$1,234.50","1234.50","$1234.50"— not numbers, statuscomes in mixed case —Completed,completed,COMPLETED,- and some orders point at a
region_idthat isn’t inregions.csvat all.
That last one is the trap: join the feed to regions with a plain inner join and those orders
vanish silently, so the revenue total comes out too low and nobody notices.
Your deliverable
Write two files into out/:
clean_orders.csv— one row per completed order after cleaning:order_id, region_id, region_name, net_amount(unmatched regions labelledUnknown, not dropped).report.json— with:clean_completed_orders— how many completed orders remain after de-duplicating,net_revenue— the corrected completed net revenue,revenue_dropped_by_naive_inner_join— how much completed revenue a plain inner join toregionswould have silently dropped (this is the “why it looked low”).
Run it
python data/make_data.py # once — generates data/ (synthetic, seeded)python starter.py # your working file; it starts naive and wrongpytest test_solution.py -qThe starter.py already produces the right output shape with the wrong numbers — fix the
three # TODOs. You’re done when all three tests pass: your net_revenue lands within 0.5%
of the truth, your completed-order count is exact, and you’ve quantified the join loss. A naive
read (inner join, no de-dup, money left as text) understates revenue by ~11% and fails.
Why this is a cross-domain challenge
It’s deliberately not solvable from one skill set:
- Data Engineering — repair the feed so the raw amounts and counts are trustworthy, and make sure attributing a region to each order can’t quietly lose any of them.
- Data Analytics — define the KPI correctly (completed only, once each) and quantify the error the naive pipeline introduced, so the figure is defensible.
Clean the numbers but let the region step drop orders and your figure is confidently low; stop that but miss the repeats and you double-count. Both halves have to be right.
Self-check (before you trust it)
- Completed net revenue should be well above the naive inner-join figure — if they’re equal, you didn’t find the orphan regions.
- Re-running
python data/make_data.pynever changes the data (it’s seeded), so your number shouldn’t move between runs. revenue_dropped_by_naive_inner_joinshould be a chunky, non-zero slice of the total — that gap is the whole point of the exercise.