polars qcut

For dataframe.

Bin continuous values into discrete categories based on their quantiles for a series.

warning This command requires a plugin The polars qcut command resides in the polars plugin. To use this command, you must install and register nu_plugin_polars. See the Plugins chapter in the book for more information.

Command Type

plugin

Signature

> polars qcut {flags} (quantiles)

Flags

  • --labels, -l {list<string>}: Names of the categories. The number of labels must be equal to the number of cut points plus one.
  • --left_closed, -c: Set the intervals to be left-closed instead of right-closed.
  • --include_breaks, -b: Include a column with the right endpoint of the bin each observation falls in. This will change the data type of the output from a Categorical to a Struct.
  • --allow_duplicates, -d: If set, duplicates in the resulting quantiles are dropped, rather than raising an error. This can happen even with unique probabilities, depending on the data.

Parameters

  • quantiles: Either a list of quantile probabilities between 0 and 1 or a positive integer determining the number of bins with uniform probability.

Input/output types:

input output
polars_dataframe polars_dataframe
polars_lazyframe polars_lazyframe

Examples

Divide a column into three categories according to pre-defined quantile probabilities.

> [-2, -1, 0, 1, 2] | polars into-df | polars qcut [0.25, 0.75] --labels ["a", "b", "c"]

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.