Skip to content

Filter groups with a list of predicates after aggregation

Source code

Description

Using this method is equivalent to adding the predicates to the aggregation and filtering afterwards.

This method can be chained and all conditions will be combined using &.

Usage

<LazyGroupBy>$having(...)

Arguments

\<dynamic-dots\> Expression that evaluates to a boolean Series.

Value

A lazy groupby

Examples

library("polars")

lf <- pl$LazyFrame(x = c("a", "b", "a", "b", "c"))

# Only keep groups that contain more than one element:
lf$group_by("x")$having(
  pl$len() > 1
)$agg()$collect()
#> shape: (2, 1)
#> ┌─────┐
#> │ x   │
#> │ --- │
#> │ str │
#> ╞═════╡
#> │ b   │
#> │ a   │
#> └─────┘