Pandas transform series values until condition is met without for loop
Use a combination of Series.cummax() and Series.shift()
a = pd.Series([0,0,1,0,0,1])

a.cummax()                               # [0,0,1,1,1,1]

a.cummax().shift(fill_value=0)           # [0,0,0,1,1,1]

Then &quot;invert&quot; the 0's and 1's
df = 1 - a.cummax().shift(fill_value=0)  # [1,1,1,0,0,0]