polars.Series.hist#

Series.hist(
bins: list[float] | None = None,
*,
bin_count: int | None = None,
include_category: bool = True,
include_breakpoint: bool = True,
) DataFrame[source]#

Bin values into buckets and count their occurrences.

Warning

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

Parameters:
bins

Bin edges. If None given, we determine the edges based on the data.

bin_count

If bins is not provided, bin_count uniform bins are created that fully encompass the data.

include_breakpoint

Include a column that indicates the upper breakpoint.

include_category

Include a column that shows the intervals as categories.

Returns:
DataFrame

Examples

>>> a = pl.Series("a", [1, 3, 8, 8, 2, 1, 3])
>>> a.hist(bin_count=4)
shape: (4, 3)
┌────────────┬─────────────┬───────┐
│ breakpoint ┆ category    ┆ count │
│ ---        ┆ ---         ┆ ---   │
│ f64        ┆ cat         ┆ u32   │
╞════════════╪═════════════╪═══════╡
│ 2.75       ┆ [1.0, 2.75] ┆ 3     │
│ 4.5        ┆ (2.75, 4.5] ┆ 2     │
│ 6.25       ┆ (4.5, 6.25] ┆ 0     │
│ 8.0        ┆ (6.25, 8.0] ┆ 2     │
└────────────┴─────────────┴───────┘