Skip to content

Commit eea0350

Browse files
Matt MaybenoTomAugspurger
Matt Maybeno
authored andcommitted
DOC: update the pandas.core.window.Rolling.var docstring (#20233)
* DOC: update the Rolling.var docstring * remove whitespace * Addressing comments * Addressing comments 2 * args, kwargs
1 parent fc32727 commit eea0350

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
@@ -928,13 +928,62 @@ def f(arg, *args, **kwargs):
928928
ddof=ddof, **kwargs)
929929

930930
_shared_docs['var'] = dedent("""
931-
%(name)s variance
931+
Calculate unbiased %(name)s variance.
932+
933+
Normalized by N-1 by default. This can be changed using the `ddof`
934+
argument.
932935
933936
Parameters
934937
----------
935938
ddof : int, default 1
936939
Delta Degrees of Freedom. The divisor used in calculations
937-
is ``N - ddof``, where ``N`` represents the number of elements.""")
940+
is ``N - ddof``, where ``N`` represents the number of elements.
941+
*args, **kwargs
942+
For NumPy compatibility. No additional arguments are used.
943+
944+
Returns
945+
-------
946+
Series or DataFrame
947+
Returns the same object type as the caller of the %(name)s calculation.
948+
949+
See Also
950+
--------
951+
Series.%(name)s : Calling object with Series data
952+
DataFrame.%(name)s : Calling object with DataFrames
953+
Series.var : Equivalent method for Series
954+
DataFrame.var : Equivalent method for DataFrame
955+
numpy.var : Equivalent method for Numpy array
956+
957+
Notes
958+
-----
959+
The default `ddof` of 1 used in :meth:`Series.var` is different than the
960+
default `ddof` of 0 in :func:`numpy.var`.
961+
962+
A minimum of 1 period is required for the rolling calculation.
963+
964+
Examples
965+
--------
966+
>>> s = pd.Series([5, 5, 6, 7, 5, 5, 5])
967+
>>> s.rolling(3).var()
968+
0 NaN
969+
1 NaN
970+
2 0.333333
971+
3 1.000000
972+
4 1.000000
973+
5 1.333333
974+
6 0.000000
975+
dtype: float64
976+
977+
>>> s.expanding(3).var()
978+
0 NaN
979+
1 NaN
980+
2 0.333333
981+
3 0.916667
982+
4 0.800000
983+
5 0.700000
984+
6 0.619048
985+
dtype: float64
986+
""")
938987

939988
def var(self, ddof=1, *args, **kwargs):
940989
nv.validate_window_func('var', args, kwargs)
@@ -1284,7 +1333,6 @@ def std(self, ddof=1, *args, **kwargs):
12841333
return super(Rolling, self).std(ddof=ddof, **kwargs)
12851334

12861335
@Substitution(name='rolling')
1287-
@Appender(_doc_template)
12881336
@Appender(_shared_docs['var'])
12891337
def var(self, ddof=1, *args, **kwargs):
12901338
nv.validate_rolling_func('var', args, kwargs)
@@ -1547,7 +1595,6 @@ def std(self, ddof=1, *args, **kwargs):
15471595
return super(Expanding, self).std(ddof=ddof, **kwargs)
15481596

15491597
@Substitution(name='expanding')
1550-
@Appender(_doc_template)
15511598
@Appender(_shared_docs['var'])
15521599
def var(self, ddof=1, *args, **kwargs):
15531600
nv.validate_expanding_func('var', args, kwargs)

0 commit comments

Comments
 (0)