AnalystPath

Warehouses Stocking Heavy Items Too Thinly

PandasMediumMid level~10 min

Problem

Two CSV files describe storage. `warehouses.csv` holds each warehouse (`warehouse_id`, `warehouse_name`, `region`); `stock.csv` records each stocked item (`stock_id`, `warehouse_id`, `item_name`, `units`, `weight_kg`). Find warehouses with a stocking skew: the heaviest item has fewer on-hand units than the lightest item. Only consider warehouses carrying at least three distinct items. Report the skew as the lightest item's units divided by the heaviest item's units, rounded to two decimals, as `stock_skew`. Sort by `stock_skew` descending, then by `warehouse_name` alphabetically.

Input data

Example rows — the live problem includes the full dataset.

warehouses
warehouse_idwarehouse_nameregion
1North HubRiverside
2East DepotGlenford
3West YardAshbury
4South BayCarrolton
5Central CrossBelmont
stock
stock_idwarehouse_iditem_nameunitsweight_kg
11Anvil480
21Bracket405
31Clamp2012
42Girder10200
52Washer402

Expected output

Your answer should return 3 rows with the columns warehouse_name, stock_skew.

Starter code (Pandas (Python))

import pandas as pd

def find_stocking_skew(warehouses, stock) -> pd.DataFrame:
    # Your code here
    return warehouses

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