polars.Expr.sign#
- Expr.sign() Expr [source]#
Compute the element-wise sign function on numeric types.
The returned value is computed as follows:
-1 if x < 0.
1 if x > 0.
x otherwise (typically 0, but could be NaN if the input is).
Null values are preserved as-is, and the dtype of the input is preserved.
Examples
>>> df = pl.DataFrame({"a": [-9.0, -0.0, 0.0, 4.0, float("nan"), None]}) >>> df.select(pl.col.a.sign()) shape: (6, 1) ┌──────┐ │ a │ │ --- │ │ f64 │ ╞══════╡ │ -1.0 │ │ -0.0 │ │ 0.0 │ │ 1.0 │ │ NaN │ │ null │ └──────┘