All problems

Total Moved by One Transaction Type

easyPythonFilteringAggregation

Northline Bank's monthly report opens with one line per kind of transaction — how much came in as deposits, how much went out as withdrawals, how much moved as transfers — and the reporting tool is run once for each kind. Deposits are recorded as positive amounts and money leaving an account as negative, so the totals are not all going to be positive numbers, and the report wants them exactly as the arithmetic leaves them.

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 — the transaction rows are not read from input. What does arrive is a single line naming the kind of transaction this run is reporting on, spelled exactly as the type column spells it.

Task: Print the total dollar amount across the transactions whose type equals the line that arrived. Keep the sign the amounts already carry — a total of money leaving accounts is a negative number.

Example: if that kind of transaction had moved twelve dollars out, you'd print -12.

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…