I have a pandas dataframe that is datetime indexed and it looks like this:
Datetime 2020-05-11 14:00:00-03:00 0.097538 2020-05-11 14:30:00-03:00 -0.083788 2020-05-11 15:00:00-03:00 -0.074128 2020-05-11 15:30:00-03:00 0.059725 2020-05-11 16:00:00-03:00 0.041369 2020-05-11 16:30:00-03:00 0.034388 2020-05-12 10:00:00-03:00 0.006814 2020-05-12 10:30:00-03:00 -0.005308 2020-05-12 11:00:00-03:00 -0.036952 2020-05-12 11:30:00-03:00 -0.070307 2020-05-12 12:00:00-03:00 0.102004 2020-05-12 12:30:00-03:00 -0.139317 2020-05-12 13:00:00-03:00 -0.167589 2020-05-12 13:30:00-03:00 -0.179942 2020-05-12 14:00:00-03:00 0.182351 2020-05-12 14:30:00-03:00 -0.160736 2020-05-12 15:00:00-03:00 -0.150033 2020-05-12 15:30:00-03:00 -0.141862 2020-05-12 16:00:00-03:00 -0.121372 2020-05-12 16:30:00-03:00 -0.095990 Name: result_col, dtype: float64
My need is to mark the rows where it changes signal, from negative to positive and vice-versa. Any thoughts on how to achieve it?
Edit: I need +1 on the cross up and -1 on the cross down.
Let us try
import numpy as np
np.sign(data).diff().ne(0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With