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(): 是一个累加求平均过程
但是需要注意的是
如果 当前行的值是空值(或者缺失值),那么需要当前结果=之前的结果来填充
如果 不是当前行的值是空值(或者缺失值),那么需要使用非空值进行累加求和或者求平均





PandasDataFrameexpanding方法详解
Pandas的DataFrame.expanding方法提供扩展窗口计算,支持累加、求和及求平均等操作。min_periods参数定义窗口最少需要的观测值数量。当遇到缺失值时,使用之前的结果填充。默认沿行方向处理,但也可按列。method参数允许选择单列或全表操作,但需配合numba引擎使用。
1575

被折叠的 条评论
为什么被折叠?



