AnalystPath

Wallet Balances After Transfers

PandasMediumMid level~10 min

Problem

You are given two DataFrames:
- `wallets` with `wallet_id`, `holder`, `opening` (the starting balance)
- `transfers` with `transfer_id`, `sender_id`, `receiver_id`, `amount`, `sent_on`

Each transfer moves `amount` out of the sender's wallet and into the receiver's wallet. For every wallet compute its final `balance = opening + (total received) - (total sent)`. A wallet that sent or received nothing keeps its opening balance.

Return columns `wallet_id`, `holder`, `balance`, and `overdrawn`, where `overdrawn` is `'Yes'` when the final balance is negative and `'No'` otherwise. Every wallet appears in the output.

Input data

Example rows — the live problem includes the full dataset.

wallets
wallet_idholderopening
1Mireille100
2Tariq200
3Sven10000
4Liwei800
transfers
transfer_idsender_idreceiver_idamountsent_on
1134002021-08-01
2325002021-08-02
3212002021-08-03

Expected output

Your answer should return 4 rows with the columns wallet_id, holder, balance, overdrawn.

Starter code (Pandas (Python))

import pandas as pd

def wallet_balances_after_transfers(wallets, transfers) -> pd.DataFrame:
    # Your code here
    return wallets

Solve this Pandas question free

Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related Pandas questions