polars.dataframe.group_by.GroupBy.count#

GroupBy.count() DataFrame[source]#

Return the number of rows in each group.

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

Rows containing null values count towards the total.

Examples

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