You can shift values by Series.shift
with cumulative sum and compare 0
and pass to numpy.where
:
print (np.where(df.shift(fill_value=0).cumsum().eq(0), 1, 0))
[1 1 1 0 0 0]
Or convert mask to integers:
print (df.shift(fill_value=0).cumsum().eq(0).astype(int))
0 1
1 1
2 1
3 0
4 0
5 0
dtype: int32
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…