polars.lazyframe.groupby.LazyGroupBy.median#

LazyGroupBy.median() LazyFrame[source]#

Return the median per group.

Examples

>>> ldf = 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"],
...     }
... ).lazy()
>>> ldf.groupby("d", maintain_order=True).median().collect()
shape: (2, 3)
┌────────┬─────┬──────┐
│ d      ┆ a   ┆ b    │
│ ---    ┆ --- ┆ ---  │
│ str    ┆ f64 ┆ f64  │
╞════════╪═════╪══════╡
│ Apple  ┆ 2.0 ┆ 4.0  │
│ Banana ┆ 4.0 ┆ 13.0 │
└────────┴─────┴──────┘