polars.Series.clip#

Series.clip(min_val: int | float, max_val: 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:
min_val

Minimum value.

max_val

Maximum value.

Examples

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