AnalystPath

Amazon Unique Shipments per Month

PandasMediumMid levelAmazon~15 min

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_idproduct_idwarehouse_idship_date
1100W12023-01-15
2101W12023-01-20
3100W12023-01-15
4102W22023-02-10
5100W12023-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 shipments

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