1

I'm trying to do OLS with using a CSV file with dates on it. As it appears, it's not possible to use directly the date format to use as a predictor. I am trying to convert the 'Date' column to a datetime64[ns] but I get a

TypeError: invalid type promotion

error when calling the OLS method. Here's my code so far :

df = pd.read_csv('BOE-XUDLERD.csv', header=0)
df['Date'] = pd.to_datetime(df['Date'], format="%Y-%m-%d")
df['Date'] = df['Date'].astype('datetime64[ns]')

print(df['Date'])

est = sm.OLS(endog=df['Value'], exog=df['Date'], intercept=True)

I browsed many stackoverflow pages on how to get it right with dates, but I couldn't figure out how to use dates properly with OLS. If anyone has a clue ?

EDIT : data can be downloaded here : https://www.quandl.com/data/BOE/XUDLERD-Spot-exchange-rate-Euro-into-US

accpnt
  • 111
  • 9
  • Can you please clarify what is the model to be estimated here? Do you want to predict the Value using the trend resulting in one coefficient (+ intercept) in the model. Or, do you want to predict using different levels (values) of date resulting in a coefficient to estimate for each unique value of data? – Sina Jan 26 '18 at 09:05
  • Also, it would be nice if you can help us reproduce your data, https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples. – Sina Jan 26 '18 at 09:16
  • Hi, sorry for the data, I added a link to the public data used for my example in the subject. Yes, what I want to do is to predict 'Value' using 'Date' as predictor for each unique value of data. – accpnt Jan 26 '18 at 10:22
  • I managed to get it to work using 'Date' index instead of datetime64 values. I think it's a bad hack, but I seem to get proper results. – accpnt Jan 29 '18 at 09:30

0 Answers0