df = pd.DataFrame([
[1,2,3,4,np.NaN],
[1,3,5,7,np.NaN],
[0,np.NaN,np.NaN,np.NaN,8],
[5,4,3,2,1],
[0,2,4,6,8]])
print(df)
print(df.fillna(
df.rolling(window=3,min_periods=1)
))
我正在尝试使用滚动并获取AttributeError来填充Null值?
答案 0 :(得分:0)
缺少一些聚合函数,例如mean
,sum
,...:
print(df.fillna(df.rolling(window=3,min_periods=1).sum()))
0 1 2 3 4
0 1 2.0 3.0 4.0 NaN
1 1 3.0 5.0 7.0 NaN
2 0 5.0 8.0 11.0 8.0
3 5 4.0 3.0 2.0 1.0
4 0 2.0 4.0 6.0 8.0