You’re given a CSV file from a small clinic that tracks basic patient data. The file has issues due to inconsistent entries and missing information. Your goal is to clean the data and output a clean version of the CSV.
Sample of clinic_patients.csv
| patient_id | name | age | visit_date | diagnosis |
|---|---|---|---|---|
| 1 | John Doe | 28 | 2024-12-01 | Flu |
| 2 | 35 | 2025-01-15 | Cold | |
| 3 | Alice Smith | 2025-01-17 | ||
| 4 | David Lee | 41 | Allergy | |
| 5 | ||||
| 6 | Mary Stone | 29 | 2025-01-20 | Headache |
- Generate the CSV file with Python from scratch.
- Fill missing
namefields with "Unknown". - Fill missing
agefields with the average age (rounded down). - Fill missing
visit_datefields with "Unknown". - Fill missing
diagnosisfields with "Not Diagnosed". - Remove any fully empty rows (like row 5).
- Sort the data by
visit_dateascending. Put "Unknown" visit_dates at the end. - Export the clean version to cleaned_clinic_patients.csv.
- Convert
visit_dateto datetime objects for proper sorting. - Validate that
ageis always an integer after cleaning. - Add a column
needs_followupwithTrueif diagnosis is "Not Diagnosed", elseFalse