I want to calculate the future continuous increase or decrease count for each element.
Assume I have a series:
l=[10, 9, 8, 9, 10, 9, 10, 11, 10, 12, 10]
s=pd.Series(l)
The expected output is:
o=[-2, -1, 2, 1, -1, 2, 1, -1, 1, -1, 0]
Here is the explanation:
the first element is 10, the next is 9, the next is 8, so, it decrease 2 times, so the output is -2, for the third element is 8, it increase 2 times (the next is 9, 10), so output is 2.
The key point is continuous, once it has reverse data, it should be stop look forward.
How can I implement that? I think for loop is not good enough