LazyGroupBy#
The LazyGroupBy class represents a grouped lazy computation. It is created by calling LazyFrame::groupBy() and provides methods to aggregate grouped data.
Methods#
agg#
Apply custom aggregation expressions.
- param array $expressions:
Array of
Polars\Exprobjects- returns:
LazyFrame
Example:
$result = $df->lazy()
->groupBy([Expr::col('group')])
->agg([
Expr::col('value')->sum(),
Expr::col('score')->mean(),
])
->collect();
count#
Count rows per group.
first#
Get the first row per group.
last#
Get the last row per group.
head#
Get the first n rows per group.
tail#
Get the last n rows per group.
sum#
Sum all numeric columns per group.
mean#
Mean of all numeric columns per group.
median#
Median of all numeric columns per group.
min#
Minimum of all columns per group.
max#
Maximum of all columns per group.