polars.Series.sign#
- Series.sign() Series [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
>>> s = pl.Series("a", [-9.0, -0.0, 0.0, 4.0, float("nan"), None]) >>> s.sign() shape: (6,) Series: 'a' [f64] [ -1.0 -0.0 0.0 1.0 NaN null ]