I have a DataFrame that shows the behavior of a machine. This machine can be in two states: Production or cleaning. Hence, I have a dummy variable called "Production", that shows 1 when the machine is producing and 0 when it is not. I would like to know the production cycles (how many hours does the machine stay producing until it stops, and how much time it stops until it starts the whole process again). Therefore, I would like to create a column that counts how much time (how many rows) the machine is under each state, but it should reset itself when the other category appears again.
Example:
production production_cycle
1 5
1 5
1 5
1 5
1 5
0 2
0 2
1 1
0 3
0 3
0 3