A community centre's feedback survey arrives as CSV text with a header row and the columns name, age, town and rating:
1name,age,town,rating2Ana,34, leeds,43Ben,,York,54ana ,34,Leeds,45Dev,41,Bath,five
It has every problem from this module: blank ages, towns and names typed with stray spaces and odd capitals, replies saved twice, and ratings typed as words. name and town are never blank.
Write clean_survey(path). The starter code includes write_text(path, text), which saves the CSV text to a file and returns its path. Each test passes that path straight to clean_survey. Read the file with pd.read_csv(path), then clean it in this order:
name and town, then put them in title case.rating to numbers. Anything that can't be read becomes missing.Return a dictionary:
"towns": the different towns, in the order they first appear"ages": every age after filling, in row order, each rounded to 1 decimal place. If no age is known at all, the missing ones stay as None."mean_rating": the mean of the ratings that could be read, rounded to 2 decimal places, or None if none could be read"missing_ratings": how many ratings could not be read, as a whole number