在 Pandas 中,如何将字符串转换为以毫秒为单位的日期时间对象? [英] In Pandas, how to convert a string to a datetime object with milliseconds?

查看:151
本文介绍了在 Pandas 中,如何将字符串转换为以毫秒为单位的日期时间对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据框中有一列事件时间戳,看起来像2016-06-10 18:58:25:675",最后3位数字是毫秒,有没有一种有效的方法可以将此列转换为Pandas数据时间类型?

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 column to a Pandas datatime type?

当我尝试时:

pd.to_datetime('2016-06-10 18:57:35:317')

出现错误,提示未知字符串格式".

An error occurs saying "Unknown string format".

推荐答案

这样的事情应该可行

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

您可以在此处查找日期时间格式

这篇关于在 Pandas 中,如何将字符串转换为以毫秒为单位的日期时间对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆