polars.Series.filter#

Series.filter(predicate: Series | list[bool]) Self[source]#

Filter elements by a boolean mask.

The original order of the remaining elements is preserved.

Parameters:
predicate

Boolean mask.

Examples

>>> s = pl.Series("a", [1, 2, 3])
>>> mask = pl.Series("", [True, False, True])
>>> s.filter(mask)
shape: (2,)
Series: 'a' [i64]
[
        1
        3
]