0
for i,j in zip(data['Min7day'],data['close_price']):
    if i > j:
        data['New'] = 'Flat'
    else
        data['New'] = 'List'

I'm trying to insert a new column with a certain string when the condition is True. What happens is that instead of writing each row with the 'Flat or 'List' string , i get the same value in every single row. I get every row with 'Flat'.

What am I doing wrong here?

Thanks,

Steve

jpp
  • 159,742
  • 34
  • 281
  • 339
Steoli
  • 9
  • 2
  • could you post an excerpt of your data columns `Min7day` and `close_price` so the problem can be reproduced? – Landar Sep 26 '18 at 09:33

1 Answers1

1

Use np.where

Ex:

data['New'] = np.where(data['Min7day'] > data['close_price'], 'Flat', 'List')
Rakesh
  • 81,458
  • 17
  • 76
  • 113