例如:
有下面一个series
df['test']= pd.Series([0.1,0.5,-1,-1,1,1])
想实现滚动2个窗口为一个周期单位中,统计数值-1出现的次数(每滚动2个窗口后,统计值要归零) df['test'].rolling (2)
期待结果:
['nan',0,1,2,1,0]
例如:
有下面一个series
df['test']= pd.Series([0.1,0.5,-1,-1,1,1])
想实现滚动2个窗口为一个周期单位中,统计数值-1出现的次数(每滚动2个窗口后,统计值要归零) df['test'].rolling (2)
期待结果:
['nan',0,1,2,1,0]
df['test'].apply(lambda x: 1 if x == -1 else 0).rolling(2).sum()