Q:

how to run OLS regression with pandas datetime object series being independent value (x)

i guess, I am missing something basic. However, here is my question. I have time series data for 25 days, I want to run OLS regression with Y value being the time series and the X value being the datetime index. here is my code
import pandas as pd
from pandas.stats.api import ols

indx = [Timestamp('2015-06-01 00:00:00'), Timestamp('2015-06-02 00:00:00'), Timestamp('2015-06-03 00:00:00'), Timestamp('2015-06-04 00:00:00'), Timestamp('2015-06-05 00:00:00'), Timestamp('2015-06-06 00:00:00'), Timestamp('2015-06-07 00:00:00'), Timestamp('2015-06-08 00:00:00'), Timestamp('2015-06-09 00:00:00'), Timestamp('2015-06-10 00:00:00'), Timestamp('2015-06-11 00:00:00'), Timestamp('2015-06-12 00:00:00'), Timestamp('2015-06-13 00:00:00'), Timestamp('2015-06-14 00:00:00'), Timestamp('2015-06-15 00:00:00'), Timestamp('2015-06-16 00:00:00'), Timestamp('2015-06-17 00:00:00'), Timestamp('2015-06-18 00:00:00'), Timestamp('2015-06-19 00:00:00'), Timestamp('2015-06-20 00:00:00'), Timestamp('2015-06-21 00:00:00'), Timestamp('2015-06-22 00:00:00'), Timestamp('2015-06-23 00:00:00'), Timestamp('2015-06-24 00:00:00'), Timestamp('2015-06-25 00:00:00')]
col = [51.219999999999999, 51.189999999999998, 51.210000000000001, 51.229999999999997, 51.219999999999999, 51.219999999999999, 51.219999999999999, 51.229999999999997, 51.240000000000002, 51.219999999999999, 51.200000000000003, 51.200000000000003, 51.200000000000003, 51.219999999999999, 51.219999999999999, 51.219999999999999, 51.219999999999999, 51.270000000000003, 51.280000000000001, 51.280000000000001, 51.299999999999997, 51.299999999999997, 51.280000000000001, 51.280000000000001, 51.270000000000003]
df = pd.DataFrame(col,index=indx,columns=['abc'])
sumstat = ols(y=df['abc'],x=df.index)

however, i get the below error because the index is datetime object
Exception: Invalid RHS type: <class 'pandas.tseries.index.DatetimeIndex'>

A:

Add this to your code:
df['jDate'] = df.index.to_julian_date()
ols(x=df.jDate, y=df.abc)

Complete looks like:
import pandas as pd
from pandas.stats.api import ols

indx = [Timestamp('2015-06-01 00:00:00'), Timestamp('2015-06-02 00:00:00'), Timestamp('2015-06-03 00:00:00'), Timestamp('2015-06-04 00:00:00'), Timestamp('2015-06-05 00:00:00'), Timestamp('2015-06-06 00:00:00'), Timestamp('2015-06-07 00:00:00'), Timestamp('2015-06-08 00:00:00'), Timestamp('2015-06-09 00:00:00'), Timestamp('2015-06-10 00:00:00'), Timestamp('2015-06-11 00:00:00'), Timestamp('2015-06-12 00:00:00'), Timestamp('2015-06-13 00:00:00'), Timestamp('2015-06-14 00:00:00'), Timestamp('2015-06-15 00:00:00'), Timestamp('2015-06-16 00:00:00'), Timestamp('2015-06-17 00:00:00'), Timestamp('2015-06-18 00:00:00'), Timestamp('2015-06-19 00:00:00'), Timestamp('2015-06-20 00:00:00'), Timestamp('2015-06-21 00:00:00'), Timestamp('2015-06-22 00:00:00'), Timestamp('2015-06-23 00:00:00'), Timestamp('2015-06-24 00:00:00'), Timestamp('2015-06-25 00:00:00')]
col = [51.219999999999999, 51.189999999999998, 51.210000000000001, 51.229999999999997, 51.219999999999999, 51.219999999999999, 51.219999999999999, 51.229999999999997, 51.240000000000002, 51.219999999999999, 51.200000000000003, 51.200000000000003, 51.200000000000003, 51.219999999999999, 51.219999999999999, 51.219999999999999, 51.219999999999999, 51.270000000000003, 51.280000000000001, 51.280000000000001, 51.299999999999997, 51.299999999999997, 51.280000000000001, 51.280000000000001, 51.270000000000003]
df = pd.DataFrame(col,index=indx,columns=['abc'])
df['jDate'] = df.index.to_julian_date()
sumstat = ols(x=df.jDate, y=df.abc)

