Back to Practice
#0202
Fill Missing Values by Group Median
MediumPandas25 min20 XP
Problem
Fill missing score values with the median score of the same department.
Why This Matters
Group-aware imputation is more realistic than one global average when segments behave differently.
Function Signature
def fill_score_by_department_median(df):
Examples
Example 1
Inputsales: 10, missing, 20; support: 7
Outputsales missing becomes 15
The sales median is (10 + 20) / 2 = 15.
Constraints
- Return the exact requested result.
- Handle common edge cases.
- Keep the solution readable before optimizing.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputsales: 10, missing, 20; support: 7
Expectedsales missing becomes 15
The sales median is (10 + 20) / 2 = 15.
Hidden Test Categories
empty or minimal inputrepeated valueslarger realistic input