i need to add a new column of 1 and 0 using the if condition in lambda condition to rules the second one need the previous data series value(df["max_value"])
This to write a target column in a time series data for machine learning and i have 2 rules the previous target wasn't 1 and the value of the df["max_value"]>a variable called target_percentage i need to add a new column of 1 and 0 using the if condition in lambda condition to rules the second one need the previous data series value(df["max_value"])
df["max_value"]=(df["high"].rolling(days_to_target).max().shift(-days_to_target)-df["open"].shift(-1))/df["open"].shift(-1)*100
df["target"]= df['max_value'].apply(lambda x: 1 if df["max_value"].shift(-1) <target_percentage and x>target_percentage else 0)
Aucun commentaire:
Enregistrer un commentaire