Skip to content

Commit f599215

Browse files
Matt MaybenoTomAugspurger
Matt Maybeno
authored andcommitted
DOC: update pandas.core.window.Rolling.std docstring (#20235)
* DOC: update Rolling.std docstring * Addressing comments * Addressing comments 2 * var -> std
1 parent 8f24748 commit f599215

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

pandas/core/window.py

+51-4
Original file line numberDiff line numberDiff line change
@@ -857,13 +857,62 @@ def median(self, **kwargs):
857857
return self._apply('roll_median_c', 'median', **kwargs)
858858

859859
_shared_docs['std'] = dedent("""
860-
%(name)s standard deviation
860+
Calculate %(name)s standard deviation.
861+
862+
Normalized by N-1 by default. This can be changed using the `ddof`
863+
argument.
861864
862865
Parameters
863866
----------
864867
ddof : int, default 1
865868
Delta Degrees of Freedom. The divisor used in calculations
866-
is ``N - ddof``, where ``N`` represents the number of elements.""")
869+
is ``N - ddof``, where ``N`` represents the number of elements.
870+
*args, **kwargs
871+
For NumPy compatibility. No additional arguments are used.
872+
873+
Returns
874+
-------
875+
Series or DataFrame
876+
Returns the same object type as the caller of the %(name)s calculation.
877+
878+
See Also
879+
--------
880+
Series.%(name)s : Calling object with Series data
881+
DataFrame.%(name)s : Calling object with DataFrames
882+
Series.std : Equivalent method for Series
883+
DataFrame.std : Equivalent method for DataFrame
884+
numpy.std : Equivalent method for Numpy array
885+
886+
Notes
887+
-----
888+
The default `ddof` of 1 used in Series.std is different than the default
889+
`ddof` of 0 in numpy.std.
890+
891+
A minimum of one period is required for the rolling calculation.
892+
893+
Examples
894+
--------
895+
>>> s = pd.Series([5, 5, 6, 7, 5, 5, 5])
896+
>>> s.rolling(3).std()
897+
0 NaN
898+
1 NaN
899+
2 0.577350
900+
3 1.000000
901+
4 1.000000
902+
5 1.154701
903+
6 0.000000
904+
dtype: float64
905+
906+
>>> s.expanding(3).std()
907+
0 NaN
908+
1 NaN
909+
2 0.577350
910+
3 0.957427
911+
4 0.894427
912+
5 0.836660
913+
6 0.786796
914+
dtype: float64
915+
""")
867916

868917
def std(self, ddof=1, *args, **kwargs):
869918
nv.validate_window_func('std', args, kwargs)
@@ -1229,7 +1278,6 @@ def median(self, **kwargs):
12291278
return super(Rolling, self).median(**kwargs)
12301279

12311280
@Substitution(name='rolling')
1232-
@Appender(_doc_template)
12331281
@Appender(_shared_docs['std'])
12341282
def std(self, ddof=1, *args, **kwargs):
12351283
nv.validate_rolling_func('std', args, kwargs)
@@ -1493,7 +1541,6 @@ def median(self, **kwargs):
14931541
return super(Expanding, self).median(**kwargs)
14941542

14951543
@Substitution(name='expanding')
1496-
@Appender(_doc_template)
14971544
@Appender(_shared_docs['std'])
14981545
def std(self, ddof=1, *args, **kwargs):
14991546
nv.validate_expanding_func('std', args, kwargs)

0 commit comments

Comments
 (0)