pandas.DataFrame.expanding
DataFrame.expanding(min_periods=1, axis=0, method='single')[source]#
Provide expanding window calculations.
Parameters
min_periods int, default 1
Minimum number of observations in window required to have a value; otherwise, result is np.nan
.
axisint or str, default 0
If 0
or 'index'
, roll across the rows.
If 1
or 'columns'
, roll across the columns.
For Series this parameter is unused and defaults to 0.
methodstr {‘single’, ‘table’}, default ‘single’
Execute the rolling operation per single column or row ('single'
) or over the entire object ('table'
).
This argument is only implemented when specifying engine='numba'
in the method call.
expanding(): 是一个累加过程
expanding().sum(): 是一个累加求和过程
expanding().mean(): 是一个累加求平均过程
但是需要注意的是
如果 当前行的值是空值(或者缺失值),那么需要当前结果=之前的结果来填充
如果 不是当前行的值是空值(或者缺失值),那么需要使用非空值进行累加求和或者求平均