polars.Series.cut#
- Series.cut(bins: 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.
- Parameters:
- bins
Bins to create.
- labels
Labels to assign to the bins. 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
Examples
>>> a = pl.Series("a", [v / 10 for v in range(-30, 30, 5)]) >>> a.cut(bins=[-1, 1]) shape: (12, 3) ┌──────┬─────────────┬──────────────┐ │ a ┆ break_point ┆ category │ │ --- ┆ --- ┆ --- │ │ f64 ┆ f64 ┆ cat │ ╞══════╪═════════════╪══════════════╡ │ -3.0 ┆ -1.0 ┆ (-inf, -1.0] │ │ -2.5 ┆ -1.0 ┆ (-inf, -1.0] │ │ -2.0 ┆ -1.0 ┆ (-inf, -1.0] │ │ -1.5 ┆ -1.0 ┆ (-inf, -1.0] │ │ … ┆ … ┆ … │ │ 1.0 ┆ 1.0 ┆ (-1.0, 1.0] │ │ 1.5 ┆ inf ┆ (1.0, inf] │ │ 2.0 ┆ inf ┆ (1.0, inf] │ │ 2.5 ┆ inf ┆ (1.0, inf] │ └──────┴─────────────┴──────────────┘