How can I reverse the sign in the quantity column whenever the side column has a sell? All other values should not be changed. The following is simply not working, it has no effect.
df[df['side'] == 'Sell']['quantity'] = df[df['side'] == 'Sell']['quantity'] * -1
Refer to the Pandas indexing documentation, and never use chain indexing per your example when setting values.
df.loc[df.side == 'Sell', 'quantity'] *= -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With