polars.Series.zip_with

Series.zip_with(mask: polars.internals.series.Series, other: polars.internals.series.Series) polars.internals.series.Series

Where mask evaluates true, take values from self. Where mask evaluates false, take values from other.

Parameters
mask

Boolean Series.

other

Series of same type.

Returns
New Series

Examples

>>> s1 = pl.Series([1, 2, 3, 4, 5])
>>> s2 = pl.Series([5, 4, 3, 2, 1])
>>> s1.zip_with(s1 < s2, s2)
shape: (5,)
Series: '' [i64]
[
        1
        2
        3
        2
        1
]
>>> mask = pl.Series([True, False, True, False, True])
>>> s1.zip_with(mask, s2)
shape: (5,)
Series: '' [i64]
[
        1
        4
        3
        2
        5
]