polars.lazyframe.group_by.LazyGroupBy.len#

LazyGroupBy.len() LazyFrame[source]#

Return the number of rows in each group.

Rows containing null values count towards the total.

Examples

>>> lf = pl.LazyFrame(
...     {
...         "a": ["apple", "apple", "orange"],
...         "b": [1, None, 2],
...     }
... )
>>> lf.group_by("a").count().collect()  
shape: (2, 2)
┌────────┬───────┐
│ a      ┆ count │
│ ---    ┆ ---   │
│ str    ┆ u32   │
╞════════╪═══════╡
│ apple  ┆ 2     │
│ orange ┆ 1     │
└────────┴───────┘