A community centre's feedback form asks for a name, a town and an age. The replies arrive as a list of dictionaries — the shape a DataFrame is built from — and they are messy in exactly the ways this chapter warned about:
Ana sent her reply twice, typed differently each time. Ben skipped his age.
Task: write clean_replies(replies) in plain Python (no pandas needed). Return the cleaned replies as a list of dictionaries with the same three keys, where:
name and town has spaces removed from both ends and is then put in title case — what .str.strip().str.title() does to a column — so " ANA" becomes "Ana" and "MILTON KEYNES " becomes "Milton Keynes".drop_duplicates. Keep the first copy, and keep the replies in their original order.None) is filled with the mean of the known ages, counting every reply once — a repeated reply must not count twice. Round the fill value to 4 decimal places. If no age is known at all, leave the gaps as None.Known ages stay exactly as they are.
Example
Ben's age is the mean of Ana's, Cara's and Dev's: .