lundi 31 août 2020

how to create new column in pandas with if statement?

here I have a dataframe in pandas: df = pd.DataFrame(df), and saved as csv file. I am beginner in python and don't know how to deal with

pandas

as csv file

I want to add a new column in specific two conditions / type 'buy'

1. df['cross'] == up
and
2. df['low'] <= df['mi48change'] # if any value of the last 10 values from df['low'] is less than any 
value of the last 10 values from df['mi48change']
otherwise type 'ok'

for condition 2, in the 2nd attached photo, this happened 3 times (red squares), 3 times that the value of df['low'] is less than df['mi48change'] in the last 10 values, before df['cross'] == up, so new column will type 'buy'.

may be it should be as a function to create this new column?

Aucun commentaire:

Enregistrer un commentaire