'numpy.ndarray' 对象没有属性 'rolling' ,在将数组制作成数据帧之后

'numpy.ndarray' object has no attribute 'rolling' ,after making array to dataframe

我将我的 numpy 数组转换为数据帧,但错误仍然存​​在

deseanolized_df = pd.DataFrame(deseanolized)
df_ma = deseanolized_df.values.rolling(3,center=True,closed='both').mean()
df_ma.plot()

输出:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_40/956302484.py in <module>
      1 deseanolized_df = pd.DataFrame(deseanolized)
----> 2 df_ma = deseanolized_df.values.rolling(3,center=True,closed='both').mean()
      3 df_ma.plot()

AttributeError: 'numpy.ndarray' object has no attribute 'rolling'

deseanolized_df.values 是底层的 numpy 数组。基本上,您转换为数据帧以转换回 numpy。

使用:

deseanolized_df.rolling(3, center=True, closed='both').mean()