How to convert Python datetime dates to decimal/float years

前端 未结 7 1387
感动是毒
感动是毒 2020-12-09 18:18

I am looking for a way to convert datetime objects to decimal(/float) year, including fractional part. Example:

>>> obj = SomeObjet()
>>> o         


        
7条回答
  •  不知归路
    2020-12-09 19:00

    After implementing the accepted solution, I had the revelation that this modern pandas version is identical, and much simpler:

    dat['decimal_date']=dat.index.year+ (dat.index.dayofyear -1)/365
    

    Must be used on a date-time index Pandas dataframe. Adding as this solution post comes up in the top of my google search for this issue.

提交回复
热议问题