Python
#39

Compute Group-Wise Running Totals with cumsum() in Pandas

MediumPwC
Interview Question #39
Asked at PwC

Given `transactions` (customer_id, txn_date, amount), calculate a running cumulative spend `cumulative_spend` for each customer over time.

Input Table: transactions
3 rows preview
customer_idtxn_dateamount
12026-01-01100
12026-01-05200
22026-01-02500
Expected Output Structure3 rows
customer_idtxn_dateamountcumulative_spend
12026-01-01100100
12026-01-05200300
22026-01-02500500
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

Python 3.10 (Pandas)
Environment Ready

Click "Run & Test" to execute your Pandas code against the test assertions.

Chat with us