I want to program a counter with python which counts the "1-values" in the column "values". The counter has to start counting after the first 0 value in the rows.
As it is seen in the example:
- the counter value for the first three "1-values" is 0.
- after having found the first 0 and the next value is 1 the count starts working
- for each 0 value the counter is set to 0.
This is just an example. In reality, the table has more than three "1-values" at the beginning. Therefore it's desired that the code should be automated.
Values | Resulted counter values |
---|---|
1 | 0 |
1 | 0 |
1 | 0 |
0 | 0 |
1 | 1 |
1 | 2 |
1 | 3 |
1 | 4 |
0 | 0 |
1 | 1 |
1 | 2 |
1 | 3 |