median

median(x, w=Window(w=None, r=0))[source]

Median value of series over given window

Parameters
  • x (Series) – series: timeseries

  • w (Union[Window, int]) – Window or int: number of observations and ramp up to use. e.g. Window(22, 10) where 22 is the window size

and 10 the ramp up value. Window size defaults to length of series. :rtype: Series :return: timeseries of median value

Usage

Computes the median value over a given window. For each window, this function will return the middle value when all elements in the window are sorted. If the number of observations in the window is even, will return the average of the middle two values. If the window size is greater than the available data, will return median of available values:

\(d = \frac{w-1}{2}\)

\(R_t = \frac{X_{\lfloor t-d \rfloor} + X_{\lceil t-d \rceil}}{2}\)

where \(w\) is the size of the rolling window. If window is not provided, computes median over the full series

Examples

Generate price series and compute median over \(22\) observations

>>> prices = generate_series(100)
>>> median(prices, 22)

See also

mean() mode()