Generating a sequence based on value in another column in Python
I have the following data frame:
I would like to add a column with value equal to 1 if flag
is 0 and incrementally add 1 in the following rows until the next 0 is encountered (as given in the example below).
I have been able to generate the sequence, but the code is extremely slow, so is there a faster way to generate the sequence?
Category Data Science