Salary vs Department Average
Problem
**[Classic — asked at multiple companies]**
For each employee, return their salary alongside their **department's average
salary** and a boolean `above_avg` flag.
Return `name`, `department`, `salary`, `dept_avg_salary`, `above_avg`,
ordered by name.
Input data
Example rows — the live problem includes the full dataset.
employees
| employee_id | name | department | salary |
|---|---|---|---|
| 1 | Alice | Engineering | 90000 |
| 2 | Bob | Engineering | 70000 |
| 3 | Carol | Marketing | 60000 |
| 4 | Dave | Marketing | 80000 |
| 5 | Eve | HR | 50000 |
Expected output
Your answer should return 6 rows with the columns name, department, salary, dept_avg_salary, above_avg.
Starter code (Pandas (Python))
import pandas as pd
def employee_vs_dept_avg(employees: pd.DataFrame) -> pd.DataFrame:
# Your code here
return employeesSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock