polars.Series.qcut#
- Series.qcut(quantiles: list[float], *, labels: list[str] | None = None, break_point_label: str = 'break_point', category_label: str = 'category', maintain_order: bool = False) DataFrame [source]#
Bin values into discrete values based on their quantiles.
- Parameters:
- quantiles
Quaniles to create. We expect quantiles
0.0 <= quantile <= 1
- labels
Labels to assign to the quantiles. If given the length of labels must be len(bins) + 1.
- break_point_label
Name given to the breakpoint column.
- category_label
Name given to the category column.
- maintain_order
Keep the order of the original Series.
- Returns:
- DataFrame
Warning
This functionality is experimental and may change without it being considered a breaking change.
Examples
>>> a = pl.Series("a", range(-5, 3)) >>> a.qcut([0.0, 0.25, 0.75]) shape: (8, 3) ┌──────┬─────────────┬───────────────┐ │ a ┆ break_point ┆ category │ │ --- ┆ --- ┆ --- │ │ f64 ┆ f64 ┆ cat │ ╞══════╪═════════════╪═══════════════╡ │ -5.0 ┆ -5.0 ┆ (-inf, -5.0] │ │ -4.0 ┆ -3.25 ┆ (-5.0, -3.25] │ │ -3.0 ┆ 0.25 ┆ (-3.25, 0.25] │ │ -2.0 ┆ 0.25 ┆ (-3.25, 0.25] │ │ -1.0 ┆ 0.25 ┆ (-3.25, 0.25] │ │ 0.0 ┆ 0.25 ┆ (-3.25, 0.25] │ │ 1.0 ┆ inf ┆ (0.25, inf] │ │ 2.0 ┆ inf ┆ (0.25, inf] │ └──────┴─────────────┴───────────────┘