Sort by order_date and store each order's position in its customer's history (1 for their first order, 2 for the second, …) in result, in date order.
import pandas as pd
orders = pd.DataFrame({
"order_id": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
"customer_id": ["C1", "C2", "C1", "C3", "C2", "C1", "C4", "C3", "C2", "C1", "C4", "C5"],
"order_date": pd.to_datetime(["2025-01-04", "2025-01-07", "2025-01-16", "2025-01-25", "2025-02-03", "2025-02-08",
"2025-02-12", "2025-02-16", "2025-02-21", "2025-03-01", "2025-03-05", "2025-03-08"]),
"city": ["Pune", "Delhi", "Pune", "Mumbai", "Delhi", "Pune", "Jaipur", "Mumbai", "Delhi", "Pune", "Jaipur", "Pune"],
"plan": ["Gold", "Basic", "Gold", "Silver", "Gold", "Silver", "Basic", "Gold", "Silver", "Gold", "Basic", "Silver"],
"amount": [2400, 650, 1800, 3200, 900, 2100, 450, 2800, 1200, 2600, 520, 1500],
"items": [3, 1, 2, 4, 2, 3, 1, 4, 2, 3, 1, 2],
"discount_pct": [10, 0, 5, 15, 0, 10, 0, 20, 5, 10, 0, 5],
})Store your final answer in a variable named result.
Each hint gives a little more help. Try on your own first.
Run your code to see the output here.