pyspark.pandas.window.Rolling.var#

Rolling.var()[source]#

Calculate unbiased rolling variance.

Note

the current implementation of this API uses Spark’s Window without specifying partition specification. This leads to move all data into single partition in single machine and could cause serious performance degradation. Avoid this method against very large dataset.

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.

Examples

>>> s = ps.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

For DataFrame, each unbiased rolling variance is computed column-wise.

>>> df = ps.DataFrame({"A": s.to_numpy(), "B": s.to_numpy() ** 2})
>>> df.rolling(2).var()
     A      B
0  NaN    NaN
1  0.0    0.0
2  0.5   60.5
3  0.5   84.5
4  2.0  288.0
5  0.0    0.0
6  0.0    0.0