All problems

A Customer's Running Balance

mediumPythonDatesCumulative

Northline's support desk pulls the same timeline every time a transaction is disputed: the balance on the account after each transaction, in chronological order, so the line being argued about can be pinned to a moment. Which account it is changes with the case, so the account number comes in with the request.

Transactions

id customer_id amount type txn_date
1 1 500 deposit 2023-07-01
2 1 -120 withdrawal 2023-07-03
3 2 1000 deposit 2023-07-02
4 2 -300 withdrawal 2023-07-05
5 3 250 deposit 2023-07-04
6 3 -600 withdrawal 2023-07-06
7 4 800 deposit 2023-07-07
8 4 -450 withdrawal 2023-07-08
9 5 2000 deposit 2023-07-09
10 5 -1500 withdrawal 2023-07-10
11 1 -200 transfer 2023-07-11
12 3 400 deposit 2023-07-12

Input

The DataFrame above is already built for you. One line of input arrives: the customer_id of the account under investigation, as a whole number. Every account named there has at least one transaction on it.

Task: Print a Python list of that customer's balance immediately after each of their own transactions, in txn_date order, starting from a balance of 0. An account may go below zero along the way; report the balance as it stood, negative sign and all.

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…