0

I am trying to create an RSI indicator in excel using Python. I was able to create columns in the CSV file that was downloaded by Pandas datareader. However, I need to create a column for upward movement and downward movement where if there was a price increase greater than 0 than previous closing price then it should populate that difference else 0. I am not able to get that. Can someone help me? Thank you!

if msft_df['Gains/Loss'] > 0:
    msft_df['Upward Movement'] = msft_df['Gains/Loss']
else:
    msft_df['Upward Movement'] = 0
ernest_k
  • 44,416
  • 5
  • 53
  • 99
Tejas
  • 1
  • What's supposed to happen if `msft_df['Gains/Loss']` has a mix of negative and positive values? `if/else` statements don't iterate! – hpaulj Jul 07 '20 at 06:05
  • If Gains/Loss is a positive number, Upward movement should be equal to 'Gains/Loss' else it should be 0. If there is another way to do it, please feel free to suggest it. Thank you! – Tejas Jul 07 '20 at 16:32
  • `msft_df['Gains/Loss']` isn't one number; it's a Series. – hpaulj Jul 07 '20 at 16:44

0 Answers0