Python
#22

Impute Missing Values with Group Median in Pandas

MediumAmazon
Interview Question #22
Asked at Amazon

Given an employee DataFrame with `department` and `salary`, impute missing salaries using the median salary of each employee's specific department.

Input Table: employees
4 rows preview
namedepartmentsalary
AaravIT90000
BhavnaITNULL
ChiragHR60000
DivyaHRNULL
Expected Output Structure4 rows
namedepartmentsalary
AaravIT90000
BhavnaIT90000
ChiragHR60000
DivyaHR60000
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

Python 3.10 (Pandas)
Environment Ready

Click "Run & Test" to execute your Pandas code against the test assertions.

Chat with us