polars.dataframe.groupby.GroupBy.count#
- GroupBy.count() DataFrame [source]#
Count the number of values in each group.
Warning
null is deemed a value in this context.
Examples
>>> df = pl.DataFrame( ... { ... "a": [1, 2, 2, 3, 4, 5], ... "b": [0.5, 0.5, 4, 10, 13, 14], ... "c": [True, True, True, False, False, True], ... "d": ["Apple", "Orange", "Apple", "Apple", "Banana", "Banana"], ... } ... ) >>> df.groupby("d", maintain_order=True).count() shape: (3, 2) ┌────────┬───────┐ │ d ┆ count │ │ --- ┆ --- │ │ str ┆ u32 │ ╞════════╪═══════╡ │ Apple ┆ 3 │ │ Orange ┆ 1 │ │ Banana ┆ 2 │ └────────┴───────┘