polars.internals.dataframe.groupby.GroupBy.median#

GroupBy.median() DataFrame[source]#

Return the median per group.

Examples

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2, 2, 3, 4, 5],
...         "b": [0.5, 0.5, 4, 10, 13, 14],
...         "d": ["Apple", "Banana", "Apple", "Apple", "Banana", "Banana"],
...     }
... )
>>> df.groupby("d", maintain_order=True).median()
shape: (2, 3)
┌────────┬─────┬──────┐
│ d      ┆ a   ┆ b    │
│ ---    ┆ --- ┆ ---  │
│ str    ┆ f64 ┆ f64  │
╞════════╪═════╪══════╡
│ Apple  ┆ 2.0 ┆ 4.0  │
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌┤
│ Banana ┆ 4.0 ┆ 13.0 │
└────────┴─────┴──────┘