Premium problem130. Number Each Customer's Orders

Medium Locked

orders has columns order_id, customer_id and placed_at (datetime).

Add an order_number column counting each customer's orders from 1 in chronological order, so a customer's third order gets 3. Return the original columns plus order_number, sorted by customer_id then placed_at, with the index renumbered from 0.

Input

   order_id  customer_id  placed_at
0         1            7 2022-01-02
1         2            7 2022-01-01
2         3            8 2022-01-05
3         4            7 2022-01-09

Output

   order_id  customer_id  placed_at  order_number
0         2            7 2022-01-01             1
1         1            7 2022-01-02             2
2         4            7 2022-01-09             3
3         3            8 2022-01-05             1

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)