Summarise a file that is not clean
You are given a CSV of orders with columns `id`, `customer`, `amount`. About one row in fifty is unusable — a missing amount, a stray header repeated mid-file, an amount with a currency symbol in it. Produce total revenue per customer. The interesting part is not the sum; it is what you do about the rows you cannot use, and whether someone reading your output would know they existed. Pick one rule for bad rows, apply it consistently, and make the count visible in the output.
What you have to hand in
- Revenue per customer, one row per customer.
- A stated rule for unusable rows, applied consistently.
- The count of skipped rows in the output itself, not only in the write-up.
- A line saying which of skip, zero, or fail you chose and why.
The checklist, published before you start
- The numbers are the numbers asked for
The summary aggregates the right field over the right grouping.
- Aggregates the wrong field, or groups by the wrong key.
- Right idea, but the grouping or the total is off for some inputs.
- Correct field, correct grouping, correct totals.
- Correct, and the author states the grain of the output in one line.
- Imperfect rows are handled on purpose
Rows that cannot be parsed are dealt with by a stated decision rather than by a crash or a silent skip.
- Crashes on a malformed row, or drops it with no trace.
- Survives bad rows, but the handling is implicit and unreported.
- Bad rows are skipped or defaulted by an explicit, stated rule.
- The rule is stated, the count is reported, and the choice is justified against the alternatives.
- The output says what it left out
A total that silently excludes rows is a wrong total. The output makes the exclusion visible.
- The total stands alone with no indication anything was dropped.
- Mentions exclusions in prose but not in the output.
- The output carries the count of skipped rows alongside the figures.
- Carries the count and enough detail to find the offending rows again.
- A colleague could maintain it
The script is decomposed into named steps that map onto the task.
- One long block with no structure.
- Some structure, but the reader must hold too much at once.
- Named functions matching the steps of the task.
- Structure makes the method obvious without the write-up.
The skills a pass would prove
- Working with structured dataLoad a real, imperfect data file and produce a summary that states what it skipped
- Dicts and setsUse a dict or set to replace a linear scan, and explain what it costs
- Files and pathsRead and write a file safely, with paths that work on someone else's machine
- Raising and handling exceptionsHandle a specific failure without hiding the failures you did not anticipate
This brief is part of the Python Fundamentals course
Starting it starts the course: every skill above, in the order they depend on each other, with this brief at the end as the thing you hand in — marked against the checklist you have just read and nothing else.
Start the Python Fundamentals course