polars.lazyframe.group_by.LazyGroupBy.count#
- LazyGroupBy.count() LazyFrame [source]#
Count the number of values in each group.
Warning
null
is deemed a value in this context.Examples
>>> ldf = 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"], ... } ... ).lazy() >>> ldf.group_by("d", maintain_order=True).count().collect() shape: (3, 2) ┌────────┬───────┐ │ d ┆ count │ │ --- ┆ --- │ │ str ┆ u32 │ ╞════════╪═══════╡ │ Apple ┆ 3 │ │ Orange ┆ 1 │ │ Banana ┆ 2 │ └────────┴───────┘