Skip to content Skip to sidebar Skip to footer

Fitting Arma Model To Time Series Indexed By Time In Python

I am trying to fit an ARMA model to a time series stored in a pandas dataframe. The dataframe has one column of values of type numpy.float64 named 'val' and an index of pandas tim

Solution 1:

I think you need convert index to DatetimeIndex:

df.index = pd.DatetimeIndex(df.index)

Sample:

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-1512:10:231.12015-02-1512:10:231.72015-03-1512:10:238.4print 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
<statsmodels.tsa.arima_model.ARMA object at 0x000000000D5247B8>

Post a Comment for "Fitting Arma Model To Time Series Indexed By Time In Python"