-1

Picture of the dataframe1

Hi! I've been trying to figure out how I could calculate wallet balances of erc-20 tokens, but can't get this to work.The idea is simple, when the "Status" columns row value is "Sending", the value would be negative, and when it is "receiving", it would be positive. Lastly I would use groupby and calculate sums by token symbols. The problem is, I can't get the conditional statement to work. What would be a way to do this? I've tried making loop iterations but they don't seem to work.

1 Answers1

0

Assuming that df is the dataframe you presented, it's enough to select proper slice and multiply values by -1:

df.loc[df['Status'] == 'Sending', 'Value'] *= -1 

And then grouping:

df = df.groupby(['Symbol']).sum().reset_index()

The looping in pandas is not a good idea – you are able to perform operations in a more optimal, vectorised manner, so try to avoid that.

pdaawr
  • 436
  • 7
  • 16