Aggregate over a GroupBy
Description
Aggregate a DataFrame over a groupby
Usage
<GroupBy>$agg(...)
Arguments
…
|
exprs to aggregate over. … args can also be passed wrapped in a list
$agg(list(e1,e2,e3))
|
Value
aggregated DataFrame
Examples
library("polars")
pl$DataFrame(
foo = c("one", "two", "two", "one", "two"),
bar = c(5, 3, 2, 4, 1)
)$group_by("foo")$agg(
pl$col("bar")$sum()$name$suffix("_sum"),
pl$col("bar")$mean()$alias("bar_tail_sum")
)
#> shape: (2, 3)
#> ┌─────┬─────────┬──────────────┐
#> │ foo ┆ bar_sum ┆ bar_tail_sum │
#> │ --- ┆ --- ┆ --- │
#> │ str ┆ f64 ┆ f64 │
#> ╞═════╪═════════╪══════════════╡
#> │ two ┆ 6.0 ┆ 2.0 │
#> │ one ┆ 9.0 ┆ 4.5 │
#> └─────┴─────────┴──────────────┘