I have a dataframe like this
enterhigh exithigh buy_action
4149.99 4044.00 1.0
4211.08 4068.50 -1.0
4041.23 3750.08 1.0
4265.80 4103.51 -1.0
4250.94 4136.33 1.0
and I hope I can create a new column by buy_action's value, if buy_action is 1, new column
enterhigh exithigh buy_action action_price
4149.99 4044.00 1.0 4149.99
4211.08 4068.50 -1.0 4068.50
4041.23 3750.08 1.0 4041.23
4265.80 4103.51 -1.0 4103.51
4250.94 4136.33 1.0 4250.94
will take enterhigh, if it's -1, take exithigh
I tried using numpy select like
condition = ((df['buy_action'] == 1),
(df['buy_action'] == -1))
value = [df['enterhigh'],df['exithigh']]
df['action_price'] = np.select(condition,value)
but it's not working
Thank you for your helping!!