Premium problem145. Find Duplicate Transactions

Medium Locked

transactions has columns transaction_id, customer_id, timestamp (datetime) and amount. Two transactions are duplicates when customer_id, timestamp and amount all match, regardless of transaction_id.

Return one row per duplicated group, with columns customer_id, timestamp, amount and copies (how many rows are in that group, always at least 2). Sort by customer_id, timestamp then amount, and renumber the index from 0.

Input

   transaction_id  customer_id           timestamp  amount
0               1            7 2022-01-01 10:00:00     5.0
1               2            7 2022-01-01 10:00:00     5.0
2               3            7 2022-01-02 10:00:00     5.0
3               4            8 2022-01-01 09:00:00     9.0
4               5            8 2022-01-01 09:00:00     9.0

Output

   customer_id           timestamp  amount  copies
0            7 2022-01-01 10:00:00     5.0       2
1            8 2022-01-01 09:00:00     9.0       2

Premium problem

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

Implement solve(...)