AnalystPath

Overworked Hospital Staff

PandasMediumMid level~10 min

Problem

Two CSV files describe a hospital. `staff.csv` holds each staff member (`staff_id`, `staff_name`, `ward`) and `shifts.csv` holds every shift worked (`shift_id`, `staff_id`, `shift_date`, `shift_kind`, `hours`). A standard work week runs Monday through Sunday and totals 50 scheduled hours, so a week is 'overworked' when a staff member's total shift hours for that week exceed 50. Find every staff member with at least two overworked weeks. Return their `staff_name` and the count of overworked weeks as `heavy_weeks`, sorted by the count descending, then by `staff_name` alphabetically.

Input data

Example rows — the live problem includes the full dataset.

staff
staff_idstaff_nameward
1Nadia OkaforICU
2Sam PetrovER
3Iris WongPediatrics
4Diego MarinoICU
5Hana KovacER
shifts
shift_idstaff_idshift_dateshift_kindhours
112024-04-01day30
212024-04-03night25
312024-04-08day28
412024-04-10night24
522024-04-02day40

Expected output

Your answer should return 2 rows with the columns staff_name, heavy_weeks.

Starter code (Pandas (Python))

import pandas as pd

def find_overworked_staff(staff, shifts) -> pd.DataFrame:
    # Your code here
    return staff

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