VijayS
VijayS

Reputation: 25

series.sum() give NaN result

The following table show transactions between two users, I need to find the the change in net worth for each user.

enter image description here

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

enter image description here

Upvotes: 0

Views: 249

Answers (1)

Gopal Gautam
Gopal Gautam

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

Related Questions