diff --git a/pandas/core/window.py b/pandas/core/window.py index c41b07759d555..b5d386eff2423 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -857,13 +857,62 @@ def median(self, **kwargs): return self._apply('roll_median_c', 'median', **kwargs) _shared_docs['std'] = dedent(""" - %(name)s standard deviation + Calculate %(name)s standard deviation. + + Normalized by N-1 by default. This can be changed using the `ddof` + argument. Parameters ---------- ddof : int, default 1 Delta Degrees of Freedom. The divisor used in calculations - is ``N - ddof``, where ``N`` represents the number of elements.""") + is ``N - ddof``, where ``N`` represents the number of elements. + *args, **kwargs + For NumPy compatibility. No additional arguments are used. + + Returns + ------- + Series or DataFrame + Returns the same object type as the caller of the %(name)s calculation. + + See Also + -------- + Series.%(name)s : Calling object with Series data + DataFrame.%(name)s : Calling object with DataFrames + Series.std : Equivalent method for Series + DataFrame.std : Equivalent method for DataFrame + numpy.std : Equivalent method for Numpy array + + Notes + ----- + The default `ddof` of 1 used in Series.std is different than the default + `ddof` of 0 in numpy.std. + + A minimum of one period is required for the rolling calculation. + + Examples + -------- + >>> s = pd.Series([5, 5, 6, 7, 5, 5, 5]) + >>> s.rolling(3).std() + 0 NaN + 1 NaN + 2 0.577350 + 3 1.000000 + 4 1.000000 + 5 1.154701 + 6 0.000000 + dtype: float64 + + >>> s.expanding(3).std() + 0 NaN + 1 NaN + 2 0.577350 + 3 0.957427 + 4 0.894427 + 5 0.836660 + 6 0.786796 + dtype: float64 + """) def std(self, ddof=1, *args, **kwargs): nv.validate_window_func('std', args, kwargs) @@ -1250,7 +1299,6 @@ def median(self, **kwargs): return super(Rolling, self).median(**kwargs) @Substitution(name='rolling') - @Appender(_doc_template) @Appender(_shared_docs['std']) def std(self, ddof=1, *args, **kwargs): nv.validate_rolling_func('std', args, kwargs) @@ -1489,7 +1537,6 @@ def median(self, **kwargs): return super(Expanding, self).median(**kwargs) @Substitution(name='expanding') - @Appender(_doc_template) @Appender(_shared_docs['std']) def std(self, ddof=1, *args, **kwargs): nv.validate_expanding_func('std', args, kwargs)