python linear regression predict by date

前端 未结 5 1958
旧时难觅i
旧时难觅i 2021-01-01 22:34

I want to predict a value at a date in the future with simple linear regression, but I can\'t due to the date format.

This is the dataframe I have:



        
5条回答
  •  长发绾君心
    2021-01-01 23:01

    Linear regression doesn't work on date data. Therefore we need to convert it into numerical value.The following code will convert the date into numerical value:

    import datetime as dt
    data_df['Date'] = pd.to_datetime(data_df['Date'])
    data_df['Date']=data_df['Date'].map(dt.datetime.toordinal)
    

提交回复
热议问题