首页 > 解决方案 > 如何使用 pandas 将 hhmmss.ff 格式转换为日期时间

问题描述

如何转换以下时间格式:

hhmmss.ff(如 110241.22 是 11:02:41.22)

使用 pandas 进入日期/时间格式?

我尝试使用pandas.to_datetime(),但无法进行转换。这是一个例子:

hhmmss='110241.22'
pd.to_datetime(hhmmss)

谢谢

标签: pythonpandasdatetime

解决方案


您需要指定format要将时间转换为的时间。这是了解每个符号含义的有用资源。这是熊猫文档

pd.to_datetime(df['column_name'], format = '%H%M%S.%f')

推荐阅读