AnalystPath

Shifts Above the Warehouse Average

PandasHardSenior level~10 min

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.

shifts
shift_idpicker_idorders_picked
1145
1290
2312
2468
pickers
picker_idfull_namewarehouse
1MaraNorth
2TomasSouth
3PriyaSouth
4OwenNorth

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 shifts

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