Intermediate
Clean a small CSV with pandas
Write clean(text) that takes CSV text with columns name,age,city and returns a cleaned DataFrame (the starter already loads the text for you). Do these four steps in order:
1. Drop exact duplicate rows. 2. Strip spaces from name and city, and make name title case (dia becomes Dia). 3. Fill a missing age with the median (the middle value) of the known ages, then make the column type int64. 4. Reset the index so the rows are numbered 0, 1, 2, ... again.
What Check tests
- The duplicate row is removed
- Names are stripped and in title case
- Cities are stripped
- A missing age becomes the median, as an int
- It also works when no age is missing
- The index runs 0, 1, 2, ...
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.