Blank Boxes by Column

Data with PythonMedium+10 XP+10

Blank Boxes by Column

A club collects sign-up forms as a list of dictionaries, one per form. Some boxes were left blank. A blank box is either the value None, or a key that is missing from that form altogether.

Write missing_percent(replies). Return a dictionary that maps each column to the percentage of forms where that column is blank, rounded to 1 decimal place.

  • Only include columns that have at least one blank. A column with no blanks is left out.
  • List the columns in the order they first appear across the forms (the order pandas gives the columns when it builds a DataFrame from the list).
  • If there are no forms, or no blanks at all, return an empty dictionary.

Examples

replies = [{"name": "Ana", "age": 34, "city": "Leeds"}, {"name": "Ben", "age": None, "city": "York"}, {"name": "Cara", "age": 29, "city": None}, {"name": "Dev", "age": 41, "city": "Bath"}, {"name": "Eli", "age": None, "city": "York"}]
returns {'age': 40.0, 'city': 20.0}
replies = [{"name": "Ivy", "email": "ivy@mail.com"}, {"name": "Jo"}, {"name": "Kai", "email": "kai@mail.com", "phone": "0711"}]
returns {'email': 33.3, 'phone': 66.7}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run