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

<GroupBy>$having(...)

Arguments

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

Value

An object of class polars_group_by

Examples

library("polars")

df <- pl$DataFrame(x = c("a", "b", "a", "b", "c"))

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