I would like to use pandas OLS function to fit a trendline to my data Series. Does anyone knows how to use the datetime index from the pandas Series as predictor in the OLS?
For example, let say that I have a simple time series:
>>> ts
2001-12-31 19.828763
2002-12-31 20.112191
2003-12-31 19.509116
2004-12-31 19.913656
2005-12-31 19.701649
2006-12-31 20.022819
2007-12-31 20.103024
2008-12-31 20.132712
2009-12-31 19.850609
2010-12-31 19.290640
2011-12-31 19.936210
2012-12-31 19.664813
Freq: A-DEC
I would like to do an OLS on it using the index as predictor:
model = pd.ols(y=ts,x=ts.index,intercept=True)
But as x is a list of datetime index, the function returns an error. Anyone has an idea?
I could use linregress from scipy.stats but I wonder if it is possible with Pandas.
Thanks, Greg