Premium problem129. Running Total per Store

Medium Locked

sales has columns store, date (datetime) and amount.

Sorted by date within each store, add a cumulative column holding the running total of that store's amounts. Return the original columns plus cumulative, sorted by store then date, with the index renumbered from 0. The running total must restart at each store rather than carrying over.

Input

  store       date  amount
0     A 2022-01-03    30.0
1     A 2022-01-01    10.0
2     A 2022-01-02    20.0
3     B 2022-01-02     7.0
4     B 2022-01-01     5.0

Output

  store       date  amount  cumulative
0     A 2022-01-01    10.0        10.0
1     A 2022-01-02    20.0        30.0
2     A 2022-01-03    30.0        60.0
3     B 2022-01-01     5.0         5.0
4     B 2022-01-02     7.0        12.0

Premium problem

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

Implement solve(...)