polars.Series.clip
-
Set values outside the given boundaries to the boundary value.
- Parameters:
-
- lower_bound
-
Lower bound. Accepts expression input. Non-expression inputs are parsed as literals. If set to
None(default), no lower bound is applied. - upper_bound
-
Upper bound. Accepts expression input. Non-expression inputs are parsed as literals. If set to
None(default), no upper bound is applied.
See also
Notes
This method only works for numeric and temporal columns. To clip other data types, consider writing a
when-then-otherwiseexpression. Seewhen().Examples
Specifying both a lower and upper bound:
>>> s = pl.Series([-50, 5, 50, None]) >>> s.clip(1, 10) shape: (4,) Series: '' [i64] [ 1 5 10 null ]Specifying only a single bound:
>>> s.clip(upper_bound=10) shape: (4,) Series: '' [i64] [ -50 5 10 null ]
Series.clip(
lower_bound: NumericLiteral | TemporalLiteral | IntoExprColumn | None = None,
upper_bound: NumericLiteral | TemporalLiteral | IntoExprColumn | None = None,
) → Series
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/series/api/polars.Series.clip.html