Profile November's file before you run anything
November's file just arrived. Count what is missing, repeated, impossible or out of place before the report touches it.
13 min · on a computer
Free course. Your Maestro, an AI, .
Before you touch a new file, bring back two facts from the first module: what does a single row in these monthly files stand for, and what explained the gap between October's report total and the number finance closed?
November's export just landed in data/sales_2026-11.csv. It is tempting to run report.py right away and see whether it prints a summary. Hold off on running it. A Glossary word file that opens without error is not automatically clean. When Python's csv.DictReader reads a file, it hands you every cell as a plain string and checks none of your business rules or the table's Glossary word.
If you run a report Glossary word straight over an uninspected file, two things go wrong. Some defects crash the run on the first bad row and hide any other issues further down. Worse, other defects never crash at all: they quietly shift your regional totals by counting an order twice, subtracting a negative number, or sneaking in revenue from the wrong month.
Profiling means counting what is missing, repeated, unparseable, or out of range across the whole file before any analysis runs. In a monthly sales file, four checks cover the ground:
Repeated keys against the table grain
Because the table's grain is one row per order, each
order_idmust appear once. A repeated row does real damage: a loop that sums sales adds that order a second time and inflates the total.Blank cells in required columns
An empty cell in a CSV arrives from
csv.DictReaderas"". Ifregionis blank or holds only spaces, the order either drops out of the four regional totals or creates an unnamed group inhistory.csv.Unparseable text and negative amounts
Even in a numeric column,
csv.DictReaderyields strings. Text thatfloat()cannot read raises aValueErrorand crashes the run, while a negative amount parses cleanly and quietly lowers a region's total.Dates outside the target month
A valid date from October looks fine to a date parser, so a report would add its revenue into November without warning. Every
order_datein November's file should start with"2026-11-".
In profile.py, the first check is already in place: Counter counts how many times each order_id appears and lists any that appear more than once. Write the other four in the same spirit: one list of offending order_id values per kind of problem. Convert amounts carefully: a check that crashes on the first bad value hides every problem after it. Ask your Maestro for a hint on testing whether text is a number without crashing.
Try it
Run profile.py first to see the row count and the repeated order_id. Then add the four remaining checks so the script prints the offending order_id values for each category, and let your output tell you what is inside data/sales_2026-11.csv before you inspect the raw file.
Once all five lines print, compare your output against the six rows in data/sales_2026-11.csv. Each of the five checks should flag one order_id. Together they show why profiling comes before running the report: one row would crash report.py on conversion, while four others would silently corrupt November's numbers. If any of your five lists came back empty or raised an error, share your code with your Maestro.