On this page
pandas.core.window.Rolling.var
Rolling.var(ddof=1, *args, **kwargs)
[source]-
Calculate unbiased rolling variance.
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
, whereN
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 rolling calculation.
See also
Series.rolling
- Calling object with Series data.
DataFrame.rolling
- Calling object with DataFrames.
Series.var
- Equivalent method for Series.
DataFrame.var
- Equivalent method for DataFrame.
numpy.var
- Equivalent method for Numpy array.
Notes
The default
ddof
of 1 used inSeries.var()
is different than the defaultddof
of 0 innumpy.var()
.A minimum of 1 period is required for the rolling calculation.
Examples
>>> s = pd.Series([5, 5, 6, 7, 5, 5, 5]) >>> s.rolling(3).var() 0 NaN 1 NaN 2 0.333333 3 1.000000 4 1.000000 5 1.333333 6 0.000000 dtype: float64
>>> s.expanding(3).var() 0 NaN 1 NaN 2 0.333333 3 0.916667 4 0.800000 5 0.700000 6 0.619048 dtype: float64
-
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.core.window.Rolling.var.html