Premium problem104. Month-Over-Month Revenue Change

Medium Locked

transactions has columns transaction_id, created_at (datetime) and value.

Total value by calendar month and return a DataFrame with columns month (as a "YYYY-MM" string) and revenue_change_pct, the percentage change from the previous month rounded to 2 decimal places. The first month has no predecessor and so holds NaN. Sort by month and renumber the index from 0.

Input

   transaction_id created_at  value
0               1 2021-01-10  100.0
1               2 2021-02-02  120.0
2               3 2021-02-20   30.0
3               4 2021-03-01   75.0

Output

     month  revenue_change_pct
0  2021-01                 NaN
1  2021-02                50.0
2  2021-03               -50.0

Premium problem

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

Implement solve(...)