Get the group indexes of the group by operation
Description
Usage
<Expr>$agg_groups()
Details
agg_groups() is deprecated as of polars 1.16.0. Use
df$with_row_index()$group_by(…, .maintain_order =
TRUE)$agg(pl$col(“index”)) instead.
Should be used in aggregation context only.
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(
group = rep(c("one", "two"), each = 3),
value = c(94, 95, 96, 97, 97, 99)
)
df$group_by("group", .maintain_order = TRUE)$agg(pl$col("value")$agg_groups())
#> shape: (2, 2)
#> ┌───────┬───────────┐
#> │ group ┆ value │
#> │ --- ┆ --- │
#> │ str ┆ list[u32] │
#> ╞═══════╪═══════════╡
#> │ one ┆ [0, 1, 2] │
#> │ two ┆ [3, 4, 5] │
#> └───────┴───────────┘
# Recommended approach
df$with_row_index()$group_by("group", .maintain_order = TRUE)$agg(pl$col("index"))
#> shape: (2, 2)
#> ┌───────┬───────────┐
#> │ group ┆ index │
#> │ --- ┆ --- │
#> │ str ┆ list[u32] │
#> ╞═══════╪═══════════╡
#> │ one ┆ [0, 1, 2] │
#> │ two ┆ [3, 4, 5] │
#> └───────┴───────────┘