pyspark.pandas.window.ExpandingGroupby.median#
- ExpandingGroupby.median()[source]#
Calculate the expanding median.
Added in version 4.3.0.
- Returns:
- Series or DataFrame
Returned object type is determined by the caller of the expanding calculation.
See also
pyspark.pandas.Series.expandingCalling expanding with Series data.
pyspark.pandas.DataFrame.expandingCalling expanding with DataFrames.
pyspark.pandas.Series.medianEquivalent method for Series.
pyspark.pandas.DataFrame.medianEquivalent method for DataFrame.
Notes
median in pandas-on-Spark uses distributed percentile approximation algorithm unlike pandas, the result might be different with pandas.
Examples
>>> s = ps.Series([2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5]) >>> s.groupby(s).expanding(3).median().sort_index() 2 0 NaN 1 NaN 3 2 NaN 3 NaN 4 3.0 4 5 NaN 6 NaN 7 4.0 8 4.0 5 9 NaN 10 NaN dtype: float64