polars math sign for dataframe
Compute the element-wise sign of a column expression, returning -1, 0, or 1.
Signature
> polars math sign {flags}
Input/output types:
| input | output |
|---|---|
| polars_expression | polars_expression |
| polars_selector | polars_expression |
Examples
Compute the element-wise sign of an integer column
> [[a]; [0] [-1] [2] [-3] [4]] | polars into-df | polars select (polars col a | polars math sign) | polars collect
╭───┬────╮
│ # │ a │
├───┼────┤
│ 0 │ 0 │
│ 1 │ -1 │
│ 2 │ 1 │
│ 3 │ -1 │
│ 4 │ 1 │
╰───┴────╯