Shifts Above the Warehouse Average
Problem
The `shifts` DataFrame records, for each picker, how many orders they handled on a given shift: `shift_id`, `picker_id`, and `orders_picked`. The `pickers` DataFrame maps each `picker_id` to a `full_name` and the `warehouse` they belong to.
A warehouse's average load is the average of `orders_picked` across every shift worked by pickers assigned to that warehouse. Find every shift whose `orders_picked` is strictly greater than the average load of the picker's warehouse.
Return `picker_id`, `shift_id`, `full_name` renamed to `picker_name`, and `orders_picked` renamed to `shift_orders`, ordered by `picker_id` then `shift_id`.
Input data
Example rows — the live problem includes the full dataset.
| shift_id | picker_id | orders_picked |
|---|---|---|
| 1 | 1 | 45 |
| 1 | 2 | 90 |
| 2 | 3 | 12 |
| 2 | 4 | 68 |
| picker_id | full_name | warehouse |
|---|---|---|
| 1 | Mara | North |
| 2 | Tomas | South |
| 3 | Priya | South |
| 4 | Owen | North |
Expected output
Your answer should return 2 rows with the columns picker_id, shift_id, picker_name, shift_orders.
Starter code (Pandas (Python))
import pandas as pd
def shifts_above_avg(shifts, pickers) -> pd.DataFrame:
# Your code here
return shiftsSolve 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