Reputation: 25
The following table show transactions between two users, I need to find the the change in net worth for each user.
I used following code, but it give be incorrect result for user 4 & 5
credit = ts.groupby('sender').sum()
debit = ts.groupby('receiver').sum()
net_change = debit - credit
net_change
Upvotes: 0
Views: 249
Reputation: 369
Edited:
You can use pandas' DataFrame.subtract to subtract dataframe where you can specify what value to fill if same index aren't available on both dataframe
credit = ts.groupby('sender').sum()
debit = ts.groupby('receiver').sum()
net_change = debit.subtract(credit, fill_value=0)
net_change
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.subtract.html
Upvotes: 1