python linear regression predict by date

前端 未结 5 1959
旧时难觅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:04

    When using

    dt.datetime.toordinal
    

    be careful that it only converts dates values and does not take into account minutes, seconds etc.. For a complete answer on generating ordinals from full datetime objects you can use something like:

    df['Datetime column'].apply(lambda x: time.mktime(x.timetuple()))
    

提交回复
热议问题