I have a data frame (df) with different "price"s and I want to compare these prices and make a decision.
df['Decision'] = np.where((df['price1'] > df['price2']) ,'sell',np.where((df['price1'] < df['price2']),'buy',np.nan))
My output is:
price1 | price2 | Decision |
---|---|---|
50 | 50 | NaN |
100 | 200 | buy |
70 | 140 | buy |
150 | 200 | buy |
150 | 50 | sell |
60 | 20 | sell |
But I want to have just the "first signal" of "buy" or "sell" and delete replication until the next signal, as:
price1 | price2 | Decision |
---|---|---|
50 | 50 | NaN |
100 | 200 | buy |
70 | 140 | |
150 | 200 | |
150 | 50 | sell |
60 | 20 |