AnalystPath

Salary vs Department Average

PandasMediumMid level~15 min

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_idnamedepartmentsalary
1AliceEngineering90000
2BobEngineering70000
3CarolMarketing60000
4DaveMarketing80000
5EveHR50000

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 employees

Solve 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

Related Pandas questions