gpt4 book ai didi

python - 我收到此错误时间数据 '27:07.5' 与格式 '%H:%M:%S'(匹配)不匹配

转载 作者:太空宇宙 更新时间:2023-11-03 20:32:03 25 4
gpt4 key购买 nike

我试图找出此 DataFrame 中 StartTime 和 LastTime(分钟)之间的差异:

StartTime     LastTime  
1 00:02:05 00:02:05
2 00:07:05 00:07:05
3 00:12:06 00:12:06
4 00:17:06 00:17:06

当我在数据上运行以下代码时

from datetime import datetime

date_format = "%H:%M.%S"

# You could also pass datetime.time object in this part and convert it to string.
time_start = str(UDP_interval['StartTime'])
time_end = str(UDP_interval['LastTime'])

# Then get the difference here.
diff = datetime.strptime(time_end, date_format) -
datetime.strptime(time_start, date_format)

# Get the time in hours i.e. 9.60, 8.5
result = diff.seconds / 3600;

我收到此错误:

dtype: object' 与格式 '%H:%M:%S' 不匹配

最佳答案

你可能应该使用:

t_start = list(map(int, str(UDP_interval['StartTime']).split(':'))) # get hours, minutes, seconds separately
t_end = list(map(int, str(UDP_interval['LastTime']).split(':')))
diff = (t_start[0] - t_end[0]) + (t_start[1] - t_start[1]) / 60 + (t_start[2] - t_start[2]) / 3600

关于python - 我收到此错误时间数据 '27:07.5' 与格式 '%H:%M:%S'(匹配)不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57436382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com