0

I have the following dataframe 'data' :

Month Revenue Index
1920-01-01 1.72
1920-02-01 1.83
1920-03-01 1.94
... ...
2021-10-01 114.20
2021-11-01 115.94
2021-12-01 116.01

I am trying to draw differencing plots and ACF plots since it is a time series. I am trying to do this with the following code:

fig, axes = plt.subplots(3, 2, sharex=True)
axes[0, 0].plot(data['Revenue Index']); axes[0, 0].set_title('Original Series')
plot_acf(data['Revenue Index'], ax=axes[0, 1])

axes[1, 0].plot(data['Revenue Index'].diff()); axes[1, 0].set_title('1st Order Differencing')
plot_acf(data['Revenue Index'].diff().dropna(), ax=axes[1, 1])

axes[2, 0].plot(data['Revenue Index'].diff().diff()); axes[2, 0].set_title('2nd Order Differencing')
plot_acf(data['Revenue Index'].diff().diff().dropna(), ax=axes[2, 1])

plt.show()

And the output of this code should look like this:

enter image description here

But unfortunately I get the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-d4f41541459e> in <module>()
      9 plot_acf(df['Consumptieprijsindex'].diff().diff().dropna(), ax=axes[2, 1])
     10 
---> 11 plt.show()

10 frames
/usr/local/lib/python3.7/dist-packages/matplotlib/dates.py in viewlim_to_dt(self)
   1096                              'often happens if you pass a non-datetime '
   1097                              'value to an axis that has datetime units'
-> 1098                              .format(vmin))
   1099         return num2date(vmin, self.tz), num2date(vmax, self.tz)
   1100 

ValueError: view limit minimum -36906.25 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units

The Month column is already set as Index and it is DateTime format. It is good to mention that some monthly values are missing during WW2, I don't know if that is the reason why I get this error.

Does somebody know why my code is not working? Thanks!

SDR3078
  • 45
  • 8

0 Answers0