Substract two expressions
Description
Method equivalent of subtraction operator expr - other
.
Usage
<Expr>$sub(other)
Arguments
other
|
Numeric literal or expression value. |
Value
Expr
See Also
- Arithmetic operators
Examples
library("polars")
df = pl$DataFrame(x = 0:4)
df$with_columns(
`x-2` = pl$col("x")$sub(2),
`x-expr` = pl$col("x")$sub(pl$col("x")$cum_sum())
)
#> shape: (5, 3)
#> ┌─────┬──────┬────────┐
#> │ x ┆ x-2 ┆ x-expr │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ f64 ┆ i32 │
#> ╞═════╪══════╪════════╡
#> │ 0 ┆ -2.0 ┆ 0 │
#> │ 1 ┆ -1.0 ┆ 0 │
#> │ 2 ┆ 0.0 ┆ -1 │
#> │ 3 ┆ 1.0 ┆ -3 │
#> │ 4 ┆ 2.0 ┆ -6 │
#> └─────┴──────┴────────┘