'Error: ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting
So I have a CSV file with two columns: date and price, but when I tried to use ARIMA on that time series I encountered this error:
ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.
' ignored when e.g. forecasting.', ValueWarning)
So I found these two questions:
ValueWarning: No frequency information was provided, so inferred frequency MS will be used
https://stackoverflow.com/a/35860703
But when I tried to run the code in the example ( the 2nd link ) :
import pandas as pd
from statsmodels.tsa.arima_model import ARMA
df=pd.DataFrame({"val": pd.Series([1.1,1.7,8.4 ],
index=['2015-01-15 12:10:23','2015-02-15 12:10:23','2015-03-15 12:10:23'])})
print df
'''
val
2015-01-15 12:10:23 1.1
2015-02-15 12:10:23 1.7
2015-03-15 12:10:23 8.4
'''
print df.index
'''
Index([u'2015-01-15 12:10:23',u'2015-02-15 12:10:23',u'2015-03-15 12:10:23'], dtype='object')
'''
df.index = pd.DatetimeIndex(df.index)
print df.index
'''
DatetimeIndex(['2015-01-15 12:10:23', '2015-02-15 12:10:23',
'2015-03-15 12:10:23'],
dtype='datetime64[ns]', freq=None)
'''
model = ARMA(df["val"], (1,0))
print model
I also received the same ValueWarning, so I tried to change this line:
df.index = pd.DatetimeIndex(df.index)
to this:
df.index = pd.DatetimeIndex(df.index.values, freq=df.index.inferred_freq)
But then I get this error:
AttributeError: 'Index' object has no attribute 'inferred_freq'
Solution 1:[1]
You current index, as printed, is string index. You should convert it to DatetimeIndex and pass a frequency by to_period:
df.index = pd.DatetimeIndex(df.index).to_period('M')
Solution 2:[2]
If your time series is irregular, you might end up receiving an error like this.
"ValueError: Inferred frequency None from passed values does not conform to passed frequency M"
Depending on what you want to do with you data, you could try different things.
What worked for me was pandas resampling, better explained here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Quang Hoang |
| Solution 2 | sebastien dupon |
