In Pandas, how to convert a string to a datetime object with milliseconds?

前端 未结 2 1292
走了就别回头了
走了就别回头了 2021-01-13 10:28

I have a column of event\'s timestamp in my dataframe, looks like \"2016-06-10 18:58:25:675\", the last 3 digits are milliseconds, is there a efficient way to transform this

相关标签:
2条回答
  • 2021-01-13 11:19

    Something like this should work

    pd.to_datetime('2016-06-10 18:57:35:317', format="%Y-%m-%d %H:%M:%S:%f")
    

    You can look up datetime formats here

    0 讨论(0)
  • 2021-01-13 11:30

    Normally there is a period / full-stop between the seconds and microseconds.

    Since your data does not have that you can specify how your data is formatted:

    pd.to_datetime('2016-06-10 18:57:35:317', format='%Y-%m-%d %H:%M:%S:%f')
    
    0 讨论(0)
提交回复
热议问题