I would like to create a column in a dataframe with stock prices that is conditional on the boolean values from another calculation.
close high low
Index
0 10 11 10
1 11 12 10
2 10 11 9
First I want to define some condition(s) that could logically look like that but in fact are a lengthy :
condition1: if df.close > df.close.shift() return True
In real I want to define many more conditions that all deliver True or False. Then I include that in the np.where():
df['NewColumn'] = np.where(condition1() == True, 'A', 'B')
I tried to define the condition as a function but did not manage to correctly set it up. I would like to avoid to write the content of the condition directly into the np.where() because it would become too complex with several nested conditions.
So, how can I accomplish my task most efficiently?
Edit: a function could look like this (but it does not work in the np.where() above):
def condition1():
if df.Close > df.Close.shift(1):
return True
Else
return False