Return the number of rows in the context$
Description
This is similar to COUNT(*)
in
SQL.
Usage
pl$len()
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(
a = c(1, 2, NA),
b = c(3, NA, NA),
c = c("foo", "bar", "foo"),
)
df$select(pl$len())
#> shape: (1, 1)
#> ┌─────┐
#> │ len │
#> │ --- │
#> │ u32 │
#> ╞═════╡
#> │ 3 │
#> └─────┘
# Generate an index column by using len in conjunction with $int_range()
df$with_columns(
pl$int_range(pl$len(), dtype = pl$UInt32)$alias("index")
)
#> shape: (3, 4)
#> ┌──────┬──────┬─────┬───────┐
#> │ a ┆ b ┆ c ┆ index │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ f64 ┆ f64 ┆ str ┆ u32 │
#> ╞══════╪══════╪═════╪═══════╡
#> │ 1.0 ┆ 3.0 ┆ foo ┆ 0 │
#> │ 2.0 ┆ null ┆ bar ┆ 1 │
#> │ null ┆ null ┆ foo ┆ 2 │
#> └──────┴──────┴─────┴───────┘