Overworked Hospital Staff
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_id | staff_name | ward |
|---|---|---|
| 1 | Nadia Okafor | ICU |
| 2 | Sam Petrov | ER |
| 3 | Iris Wong | Pediatrics |
| 4 | Diego Marino | ICU |
| 5 | Hana Kovac | ER |
| shift_id | staff_id | shift_date | shift_kind | hours |
|---|---|---|---|---|
| 1 | 1 | 2024-04-01 | day | 30 |
| 2 | 1 | 2024-04-03 | night | 25 |
| 3 | 1 | 2024-04-08 | day | 28 |
| 4 | 1 | 2024-04-10 | night | 24 |
| 5 | 2 | 2024-04-02 | day | 40 |
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 staffSolve 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