AnalystPath

Average Compensation by Title and Gender

PandasMediumMid level~15 min

Problem

**[Classic — multi-table HR analytics]**

Three tables: `employees` (with `title_id`, `gender`), `titles`
(with `title_name`), and `compensation` (with `base_salary`, `bonus`).

For each combination of title and gender, compute the **average total
compensation** (base + bonus).

Return `title_name`, `gender`, `avg_compensation`, ordered by title then gender.

Input data

Example rows — the live problem includes the full dataset.

employees
employee_idnametitle_idgender
1Alice1F
2Bob1M
3Carol2F
4Dave2M
5Eve1F
titles
title_idtitle_name
1Engineer
2Manager
compensation
employee_idbase_salarybonus
1800005000
2850006000
310000010000
410500012000
5780004000

Expected output

Your answer should return 4 rows with the columns title_name, gender, avg_compensation.

Starter code (Pandas (Python))

import pandas as pd

def avg_compensation(employees: pd.DataFrame, titles: pd.DataFrame, compensation: 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