polars.Expr.clip_max#
- Expr.clip_max(upper_bound: int | float) Self [source]#
Clip (limit) the values in an array to a 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:
- upper_bound
Upper bound.
Examples
>>> df = pl.DataFrame({"foo": [-50, 5, None, 50]}) >>> df.with_columns(pl.col("foo").clip_max(0).alias("foo_clipped")) shape: (4, 2) ┌──────┬─────────────┐ │ foo ┆ foo_clipped │ │ --- ┆ --- │ │ i64 ┆ i64 │ ╞══════╪═════════════╡ │ -50 ┆ -50 │ │ 5 ┆ 0 │ │ null ┆ null │ │ 50 ┆ 0 │ └──────┴─────────────┘