pandas.DataFrame.expanding or pandas.Series.expanding

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

pandas.DataFrame.expanding

DataFrame.expanding(min_periods=1axis=0method='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(): 是一个累加求平均过程

但是需要注意的是

如果 当前行的值是空值(或者缺失值),那么需要当前结果=之前的结果来填充

如果 不是当前行的值是空值(或者缺失值),那么需要使用非空值进行累加求和或者求平均

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LIQING LIN

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值