Floor divide two expressions
Description
Method equivalent of floor division operator expr %/%
other
.
Usage
<Expr>$floor_div(other)
Arguments
other
|
Numeric literal or expression value. |
Value
Expr
See Also
- Arithmetic operators
-
\
$div() -
\
$mod()
Examples
library("polars")
df = pl$DataFrame(x = 1:5)
df$with_columns(
`x/2` = pl$col("x")$div(2),
`x%/%2` = pl$col("x")$floor_div(2)
)
#> shape: (5, 3)
#> ┌─────┬─────┬───────┐
#> │ x ┆ x/2 ┆ x%/%2 │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ f64 ┆ f64 │
#> ╞═════╪═════╪═══════╡
#> │ 1 ┆ 0.5 ┆ 0.0 │
#> │ 2 ┆ 1.0 ┆ 1.0 │
#> │ 3 ┆ 1.5 ┆ 1.0 │
#> │ 4 ┆ 2.0 ┆ 2.0 │
#> │ 5 ┆ 2.5 ┆ 2.0 │
#> └─────┴─────┴───────┘