I have a 'signal' series with 1 values (on), -1 values (off) and zero values:
signal = pd.Series([0, 1, 0, 0, -1, 0, 1, 1, 0, -1])
I need to return the number of rows between contiguous on and off signals, below the result:
first_occurrence = 3
second_occurrence = 2
To take in consideration when two or more contiguous on values are present, the reference is the last one.
Many thanks in advance.
Regards Tom