Skip to content

Get the group indexes of the group by operation

Description

Should be used in aggregation context only.

Usage

<Expr>$agg_groups()

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, 3)
#> ┌───────┬────────────────┬───────────┐
#> │ group ┆ maintain_order ┆ value     │
#> │ ---   ┆ ---            ┆ ---       │
#> │ str   ┆ bool           ┆ list[u32] │
#> ╞═══════╪════════════════╪═══════════╡
#> │ two   ┆ true           ┆ [3, 4, 5] │
#> │ one   ┆ true           ┆ [0, 1, 2] │
#> └───────┴────────────────┴───────────┘