Exercise · Beginner
Read this export without breaking it
One CSV, six defects, and a read that has to survive all of them. Write the read_csv call and the four checks that prove it worked, then say what each defect would have cost.
Every defect in this exercise is in the file you already have. None of them raise. All of them change a number.
The file
muac-screening-artibonite-2024.v1.csv — 4,218 screening records from twelve
communes in Artibonite, Haiti. Synthetic, and shaped like the real thing.
The task
Write a single read_csv call, plus whatever follows it, that produces a
DataFrame in which:
muac_mmcontains no value that means “not measured”child_idandcommuneare text, not numbersscreening_dateis a datetime, parsed with an explicit formatoutcomeis a categorical with a declared vocabularyoedemais a nullable boolean —True,Falseor missing, never a string- the row count is asserted, so a truncated file fails rather than reporting a smaller caseload
Then write the four checks from lesson 3 — shape, dtypes, missing, first row — and run them.
What to hand in
A single Python file that runs top to bottom and prints:
- the mean MUAC before and after the sentinel is declared
- the number of records excluded by each of the six decisions above
- the count of
outcomevalues that fell outside your declared vocabulary - the count of
oedemavalues your boolean map did not cover
The questions to answer in prose
Three sentences each. These are the exercise; the code is how you get to them.
1. The mean MUAC moves when you declare the sentinel. By how much, in which direction, and why is the wrong figure harder to catch than an obviously broken one?
2. Two communes recorded oedema as Y/N rather than true/false. If you
had cast that column with astype(bool) instead of mapping it, what would every
"false" have become, and what would that have done to the SAM count?
3. Your outcome categorical turned some values into missing. Which values,
how many rows, and what should happen next — is this a cleaning decision, a
question for whoever entered the data, or both?
How to know you are done
Someone else should be able to run your file on a fresh checkout and get the same
printed numbers. If your file contains a path that starts with /Users or C:,
you are not done — see lesson 2.
What this exercise is not
It is not asking you to decide what to do about the missing values. Dropping, imputing or reporting them separately is an analysis decision that belongs in a cleaning log, and Data Analysis Foundations covers it. Here you are only making sure a code stops pretending to be a measurement.