Cumulative View of Booleans

28 views Asked by At

If I have a series that is [False, False, True, False, True, False]

I would like to return a cumulative view of [False, False, True, True, True, True]

Right now I tend to use cumsum and then follow up with a np.where(series > 0, True, False).

But I'm wondering if there is a more efficient way to do this.

1

There are 1 answers

0
mozway On BEST ANSWER

What you want is a cummax:

pd.Series([False, False, True, False, True, False]).cummax()

Output:

0    False
1    False
2     True
3     True
4     True
5     True
dtype: bool