polars.dataframe.group_by.GroupBy.quantile#

GroupBy.quantile(
quantile: float,
interpolation: RollingInterpolationMethod = 'nearest',
) DataFrame[source]#

Compute the quantile per group.

Parameters:
quantile

Quantile between 0.0 and 1.0.

interpolation{‘nearest’, ‘higher’, ‘lower’, ‘midpoint’, ‘linear’}

Interpolation method.

Examples

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2, 2, 3, 4, 5],
...         "b": [0.5, 0.5, 4, 10, 13, 14],
...         "d": ["Apple", "Orange", "Apple", "Apple", "Banana", "Banana"],
...     }
... )
>>> df.group_by("d", maintain_order=True).quantile(1)
shape: (3, 3)
┌────────┬─────┬──────┐
│ d      ┆ a   ┆ b    │
│ ---    ┆ --- ┆ ---  │
│ str    ┆ f64 ┆ f64  │
╞════════╪═════╪══════╡
│ Apple  ┆ 3.0 ┆ 10.0 │
│ Orange ┆ 2.0 ┆ 0.5  │
│ Banana ┆ 5.0 ┆ 14.0 │
└────────┴─────┴──────┘