Home > Back-end >  'numpy.ndarray' object has no attribute 'rolling' ,after making array to datafra
'numpy.ndarray' object has no attribute 'rolling' ,after making array to datafra

Time:12-11

I converted my numpy array to dataframe, however the error still remains

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

Output:

---------------------------------------------------------------------------
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'

CodePudding user response:

deseanolized_df.values is the underlying numpy array. Basically, you converted to dataframe to convert back to numpy.

Use:

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