Lab · Data Science, Machine Learning and AI
Lab: clean a clinic's visit register
The brief
A clinic's front desk types every visit into a spreadsheet, with all the usual mistakes. Tidy the city names, turn fee text into numbers, drop repeated rows and impossible ages, fill missing fees with the median, and report visits and average fee per city.
Why it matters
Cleaning takes most of the time in real data jobs. Hospitals, diagnostic chains, insurance firms and government health schemes all receive hand-typed registers like this one, and every report built on top is wrong if the cleaning is skipped or done by hand in a different way each month.
Skills you practise
- tidying text
- converting money text safely
- removing duplicates
- handling missing values
- group summaries
What you will have at the end
clean.py: a repeatable cleaning script for the clinic register, and a short cleaning log saying what was fixed (repeats, bad ages, missing fees) and how.
How it is marked (rubric, 100 points)
| Correct cleaningAll five checks pass: names, fees, repeats, impossible ages, filled fees and the city summary. | 45 |
|---|---|
| Honest choicesMissing values stay None until you decide on purpose; the raw register is never changed. | 25 |
| Readable, reusable codeOne small function per problem, so next month's register can be cleaned with one call. | 20 |
| Cleaning logA few lines record every rule you applied and how many rows each one touched. | 10 |
0/5 steps done
Step 1 of 5
Tidy the city names
clean_city(name) strips spaces, title-cases the name and maps old names: " pune " gives "Pune", "blr" gives "Bengaluru", a blank gives None.
Computers treat " pune ", "PUNE" and "Pune" as three different cities, so a group-by would split one city into three. strip() removes the spaces and title() fixes the case. Then look the name up in ALIASES, so old or short names become one official name. A blank city is missing data: return None, not an empty string.
Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.