获取“ AttributeError:'滚动'对象没有属性'astype'”

时间:2018-11-24 17:07:02

标签: python pandas

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值?

1 个答案:

答案 0 :(得分:0)

缺少一些聚合函数,例如meansum,...:

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