Amazon Unique Shipments per Month
Problem
**[Asked at Amazon]**
Some shipments are logged multiple times. Deduplicate on the composite key
`(product_id, warehouse_id, ship_date)`, then count **unique shipments per
month**.
Return `month` (YYYY-MM) and `unique_shipments`, ordered by month.
Input data
Example rows — the live problem includes the full dataset.
shipments
| shipment_id | product_id | warehouse_id | ship_date |
|---|---|---|---|
| 1 | 100 | W1 | 2023-01-15 |
| 2 | 101 | W1 | 2023-01-20 |
| 3 | 100 | W1 | 2023-01-15 |
| 4 | 102 | W2 | 2023-02-10 |
| 5 | 100 | W1 | 2023-02-25 |
Expected output
Your answer should return 2 rows with the columns month, unique_shipments.
Starter code (Pandas (Python))
import pandas as pd
def shipments_per_month(shipments: pd.DataFrame) -> pd.DataFrame:
# Your code here
return shipmentsSolve 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