Home > database >  I want store a specific number when achieving the condition in to a list Python
I want store a specific number when achieving the condition in to a list Python

Time:12-30

I want to store 1 and -1 in a list when achieving the conditional wholesale

M1= ((data.GO> 0) & (data.GO.shift(1) < 0))*-1
M2= ((data.GO< 0) & (data.GO.shift(1) > 0))*1
data['direction'] =M1 M2

if  data['direction'].iloc[0] ==-1:
    MS= -1
if  data['direction'].iloc[0] ==1:
    MS=1
         

I want to store value MS

Explain more about what I want

enter image description here

I am new to programming sorry if there are errors in the code

CodePudding user response:

if you want MS as a list, declare a empty list MS in front of your code MS = [] After your if/else statements append the values to your list MS.append(-1) or MS.append(1)

It will give you a list [1,-1,1,1,-1 ...... ]

  • Related