# pandas.core.window.Rolling.median¶

Calculate the rolling median.

**kwargs For compatibility with other rolling methods. Has no effect on the computed median. :return: Series or DataFrame

Returned type is the same as the original object.

## Limitations¶

This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff between staying in JIT-region with that function or going back to interpreter mode.

## Examples¶

Calculate the rolling median.
import pandas as pd
from numba import njit

@njit
def series_rolling_median():
series = pd.Series([4, 3, 5, 2, 6])  # Series of 4, 3, 5, 2, 6
out_series = series.rolling(3).median()

return out_series  # Expect series of NaN, NaN, 4.0, 3.0, 5.0

print(series_rolling_median())
$python ./series/rolling/series_rolling_median.py 0 NaN 1 NaN 2 4.0 3 3.0 4 5.0 dtype: float64 Calculate the rolling median. import pandas as pd from numba import njit @njit def df_rolling_median(): df = pd.DataFrame({'A': [4, 3, 5, 2, 6], 'B': [-4, -3, -5, -2, -6]}) out_df = df.rolling(3).median() # Expect DataFrame of # {'A': [NaN, NaN, 4.0, 3.0, 5.0], 'B': [NaN, NaN, -4.0, -3.0, -5.0]} return out_df print(df_rolling_median())$ python ./dataframe/rolling/dataframe_rolling_median.py
A    B
0  NaN  NaN
1  NaN  NaN
2  4.0 -4.0
3  3.0 -3.0
4  5.0 -5.0

Series.rolling

Calling object with a Series.

DataFrame.rolling

Calling object with a DataFrame.

Series.median

Similar method for Series.

DataFrame.median

Similar method for DataFrame.