I have a df like so:
Count
1
0
1
1
0
0
1
1
1
0
and I want to return a 1
in a new column if there are two or more consecutive occurrences of 1
in Count
and a 0
if there is not. So in the new column each row would get a 1
based on this criteria being met in the column Count
. My desired output would then be:
Count New_Value
1 0
0 0
1 1
1 1
0 0
0 0
1 1
1 1
1 1
0 0
I am thinking I may need to use itertools
but I have been reading about it and haven't come across what I need yet. I would like to be able to use this method to count any number of consecutive occurrences, not just 2 as well. For example, sometimes I need to count 10 consecutive occurrences, I just use 2 in the example here.