【问题标题】:Cumulative time strings to pandas datetime format熊猫日期时间格式的累积时间字符串
【发布时间】:2020-07-14 02:35:28
【问题描述】:

我正在尝试处理一些累积小时数的时间序列数据,但是我无法正确地将时间转换为日期时间。

csv format    
cumulative_time,temperature  
01:03:10,30,  
02:03:10,31,  
...  
22:03:10,30,  
23:03:10,29,  
24:03:09,29,  
25:03:09,25,    
etc

df['cumulative_time']=pd.to_datetime(df['cumulative_time'],format='%H:%M:%S').dt.time

不断产生错误:

time data '24:03:09' does not match format '%H:%M:%S'

对如何将时间转换为日期时间格式有什么想法,尤其是当小时数超过 24 小时时?

【问题讨论】:

    标签: python pandas datetime string-to-datetime


    【解决方案1】:

    您可能需要pd.to_timedelta 函数。

    “日期时间”是一个时间点,例如。 “下午 3 点”;它在抱怨“24:03:09”,因为那是第二天 0:03:09。

    “timedelta”是经过的时间量。

    【讨论】:

    • df['cumulative_time']=pd.to_timedelta(df['cumulative_time'])
    • 非常感谢!我知道这一定很简单
    猜你喜欢
    • 2021-11-01
    • 1970-01-01
    • 2017-05-20
    • 2020-09-17
    • 2021-02-17
    • 2020-06-04
    • 2015-07-19
    • 2020-09-13
    相关资源
    最近更新 更多