polars.dataframe.group_by.GroupBy.len#

GroupBy.len() DataFrame[source]#

Return the number of rows in each group.

Examples

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