Warehouses Stocking Heavy Items Too Thinly
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.
| warehouse_id | warehouse_name | region |
|---|---|---|
| 1 | North Hub | Riverside |
| 2 | East Depot | Glenford |
| 3 | West Yard | Ashbury |
| 4 | South Bay | Carrolton |
| 5 | Central Cross | Belmont |
| stock_id | warehouse_id | item_name | units | weight_kg |
|---|---|---|---|---|
| 1 | 1 | Anvil | 4 | 80 |
| 2 | 1 | Bracket | 40 | 5 |
| 3 | 1 | Clamp | 20 | 12 |
| 4 | 2 | Girder | 10 | 200 |
| 5 | 2 | Washer | 40 | 2 |
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 warehousesSolve 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