polars.Series.clip#

Series.clip(
lower_bound: int | float,
upper_bound: int | float,
) Series[source]#

Clip (limit) the values in an array to a min and max boundary.

Only works for numerical types.

If you want to clip other dtypes, consider writing a “when, then, otherwise” expression. See when() for more information.

Parameters:
lower_bound

Minimum value.

upper_bound

Maximum value.

Examples

>>> s = pl.Series("foo", [-50, 5, None, 50])
>>> s.clip(1, 10)
shape: (4,)
Series: 'foo' [i64]
[
    1
    5
    null
    10
]