pyspark.pandas.window.Rolling.median#
- Rolling.median()[source]#
Calculate the rolling median.
Added in version 4.3.0.
Note
the current implementation of this API uses Spark’s Window without specifying partition specification. This leads to move all data into single partition in single machine and could cause serious performance degradation. Avoid this method against very large dataset.
- Returns:
- Series or DataFrame
Returned object type is determined by the caller of the rolling calculation.
See also
pyspark.pandas.Series.rollingCalling object with Series data.
pyspark.pandas.DataFrame.rollingCalling object 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([4, 3, 5, 2, 6]) >>> s 0 4 1 3 2 5 3 2 4 6 dtype: int64
>>> s.rolling(2).median() 0 NaN 1 3.0 2 3.0 3 2.0 4 2.0 dtype: float64
>>> s.rolling(3).median() 0 NaN 1 NaN 2 4.0 3 3.0 4 5.0 dtype: float64