atoti.agg.median module#

atoti.agg.median(operand, *, scope=None)#

Return a measure equal to the median of the passed measure across the specified scope.

Parameters
  • operand (Union[Column, Operation, MeasureDescription, MeasureConvertible]) – The measure or table column to aggregate.

  • scope (Optional[Scope]) – The scope of the aggregation. When None is specified, the natural aggregation scope is used: it contains all the data in the cube which coordinates match the ones of the currently evaluated member.

Example

>>> df = pd.DataFrame(
...     columns=["id", "Quantity", "Price", "Other"],
...     data=[
...         ("a1", 100, 12.5, 1),
...         ("a2", 10, 43, 2),
...         ("a3", 1000, 25.9, 2),
...     ],
... )
>>> table = session.read_pandas(
...     df,
...     table_name="Product",
...     keys=["id"],
... )
>>> table.head()
    Quantity  Price  Other
id
a1       100   12.5      1
a2        10   43.0      2
a3      1000   25.9      2
>>> cube = session.create_cube(table)
>>> m = cube.measures
>>> m["Median Price"] = tt.agg.median(table["Price"])
>>> cube.query(m["Median Price"])
  Median Price
0        25.90
Return type

MeasureDescription