Research Lab Reporting Chain Under the Director
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.
| member_id | member_name | advisor_id | stipend |
|---|---|---|---|
| 1 | Director Voss | 9000 | |
| 2 | Priya Anand | 1 | 6000 |
| 3 | Mateo Cruz | 1 | 6500 |
| 4 | Lena Hoffmann | 2 | 4000 |
| 5 | Tomas Berg | 2 | 4200 |
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_membersSolve 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