AnalystPath

Research Lab Reporting Chain Under the Director

PandasHardSenior level~10 min

Problem

You are given a DataFrame `lab_members` loaded from `lab_members.csv` with columns `member_id` (int), `member_name` (string), `advisor_id` (int or null) and `stipend` (int). The single row whose `advisor_id` is null is the lab Director. Walk the reporting tree downward from the Director: every member reachable through advisor links is a report, with `depth` = number of steps from the Director (the Director's direct reports are depth 1). For each report return `report_id` = member_id, `report_name` = member_name, `depth`, and `stipend_gap` = that member's stipend minus the Director's stipend. Exclude the Director. Sort by `depth` then `report_id`.

Input data

Example rows — the live problem includes the full dataset.

lab_members
member_idmember_nameadvisor_idstipend
1Director Voss9000
2Priya Anand16000
3Mateo Cruz16500
4Lena Hoffmann24000
5Tomas Berg24200

Expected output

Your answer should return 5 rows with the columns report_id, report_name, depth, stipend_gap.

Starter code (Pandas (Python))

import pandas as pd

def reporting_chain(lab_members) -> pd.DataFrame:
    # Your code here
    return lab_members

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