Suppose I have a dataframe like this:
ID 0 1 2 3 4 5 6 7 8 ... 81 82 83 84 85 86 87 88 89 90 total day_90
-------------------------------------------------------------------------------------------------------------
0 A 2 21 0 18 3 0 0 0 2 ... 0 0 0 0 0 0 0 0 0 0 156 47
1 B 0 20 12 2 0 8 14 23 0 ... 0 0 0 0 0 0 0 0 0 0 231 35
2 C 0 38 19 3 1 3 3 7 1 ... 0 0 0 0 0 0 0 0 0 0 78 16
3 D 3 0 0 1 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 5 3
where the last column [day_90] contains the value of which column ([0] - [90]) accumulates 90% of the [total] for each row. To clarify, take the first row as an example: in the 47th column, the ID A hits a total of 90% of 156 events that he will achieve in 90 days.
What I need is: for each row, count the length of the first sequence of 0s that is bigger than 7 (or any arbitrary number predefined). So, for example: for the first row, I want to know how long is the first sequence of zeros after column 47, but only if the sequence exceeds 7 zeros in a row. If there are 6 zeros and then a non-zero, then I don't want to count it.
Finally, I want to store this result in a new column after [day_90]. So if ID A has a sequence of 10 zeros right after column 47, I want to add a new column [0_sequence] that holds the value of 10 for that ID.
I really have no idea where to start. Any help is appreciated =)