Python
All Top Python Interview Questions#22
Impute Missing Values with Group Median in Pandas
MediumAmazonInterview Question #22
Asked at AmazonGiven an employee DataFrame with `department` and `salary`, impute missing salaries using the median salary of each employee's specific department.
Input Table: df
4 rows preview| name | department | salary |
|---|---|---|
| Aarav | IT | 90000 |
| Bhavna | IT | NULL |
| Chirag | HR | 60000 |
| Divya | HR | NULL |
Expected Output Structure4 rows
| name | department | salary |
|---|---|---|
| Aarav | IT | 90000 |
| Bhavna | IT | 90000 |
| Chirag | HR | 60000 |
| Divya | HR | 60000 |
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
Starting the real Python + pandas runtime (one-time download)…