Skip to main content
Version: 1.5.1

Expr.median

def median() -> Expr

Categories: aggregation

Aggregation operation that finds the median of the values in the group.

Examples

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ ss ┆ i │
------
str ┆ i64 │
╞══════╪══════╡
│ A ┆ 1
│ B ┆ 0
│ A ┆ 2
│ B ┆ 3
│ B ┆ 4
│ C ┆ -1
│ C ┆ -2
│ C ┆ -3
│ D ┆ -4
│ F ┆ -5
│ null ┆ null │
└──────┴──────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b")).median())
>>>
┌──────┬──────┐
│ ss ┆ i │
------
str ┆ f64 │
╞══════╪══════╡
│ F ┆ -5.0
│ C ┆ -2.0
│ B ┆ 3.0
│ D ┆ -4.0
│ A ┆ 1.5
│ null ┆ null │
└──────┴──────┘