Skip to interview prep
Apexed

2. Count and fill missing values

EasyPandas & NumPy

Rows have age and city, either of which may be None. Return a dict with missing (missing count per column, as a dict) and ages (the age column with missing values filled by the median age, as a list of floats).

Input rows arrive as a list of dictionaries; build a DataFrame with pd.DataFrame(rows).

Example 1

Input: [{'age': 30, 'city': 'Austin'}, {'age': None, 'city': None}, {'age': 40, 'city': 'Leeds'}]
Output: {'missing': {'age': 1, 'city': 1}, 'ages': [30.0, 35.0, 40.0]}

Constraints

  • At least one age is present

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 3 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Count and fill missing values — coding interview practice — Apexed