Skip to content

DOC: Improve the docstring of pandas.core.window.Rolling.median #20260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
35 changes: 32 additions & 3 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,38 @@ def mean(self, *args, **kwargs):
return self._apply('roll_mean', 'mean', **kwargs)

_shared_docs['median'] = dedent("""
%(name)s median
Calculate the %(name)s median.

Parameters
----------
**kwargs
For compatibility with other %(name)s methods. Has no effect
on the computed median.

Returns
-------
Series or DataFrame
Returned type is the same as the original object.

See Also
--------
Series.%(name)s : Calling object with Series data
DataFrame.%(name)s : Calling object with DataFrames
Series.median : Equivalent method for Series
DataFrame.median : Equivalent method for DataFrame

Examples
--------
Compute the rolling median of a series with a window size of 3.

>>> s = pd.Series([0, 1, 2, 3, 4])
>>> s.rolling(3).median()
0 NaN
1 NaN
2 1.0
3 2.0
4 3.0
dtype: float64
""")

def median(self, **kwargs):
Expand Down Expand Up @@ -1244,7 +1275,6 @@ def mean(self, *args, **kwargs):
return super(Rolling, self).mean(*args, **kwargs)

@Substitution(name='rolling')
@Appender(_doc_template)
@Appender(_shared_docs['median'])
def median(self, **kwargs):
return super(Rolling, self).median(**kwargs)
Expand Down Expand Up @@ -1483,7 +1513,6 @@ def mean(self, *args, **kwargs):
return super(Expanding, self).mean(*args, **kwargs)

@Substitution(name='expanding')
@Appender(_doc_template)
@Appender(_shared_docs['median'])
def median(self, **kwargs):
return super(Expanding, self).median(**kwargs)
Expand Down