Suppose, I have Pandas DataFrame look like below:
account have
A 1
A 2
A 1
A 1
A 1
A 1
A 1
A 1
A 1
B 1
B 1
B 1
B 2
B 1
B 1
B 1
B 1
B 1
B 1
I want the results look like below:
account want
A NaN
A NaN
A 1
A 2
A 3
A 3
A 3
A 3
A 3
B NaN
B NaN
B 3
B 2
B 1
B 2
B 3
B 3
B 3
B 3
The idea behind is that given the rolling window equal to 3. I want to find the longest consecutive count that value equal to 1. For example, in account A, the longest consecutive count that value equal to 1 given window equal to 3 is 1 (at index 2). At index 3, the result returns 2 that because given window contained values of 2, 1, 1.
Follow the same logic above and applied to account B, the results will be as shown.
Any suggestion on this process.
Thanks a lot!