polars.lazyframe.group_by.LazyGroupBy.count#

LazyGroupBy.count() LazyFrame[source]#

Return the number of rows in each group.

Deprecated since version 0.20.5: This method has been renamed to LazyGroupBy.len().

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     │
└────────┴───────┘