【发布时间】:2019-03-28 00:03:09
【问题描述】:
由我不拥有的系统提供的 excel 文件将项目或任务的工作小时数提供为 HH:MM:SS,如果它是 23 小时或更短时间,通常不会有问题。任何时候是 24 小时或更长时间,python 都会将此视为 1/1/1900 00:00:00,但源文件显示类似 37:00:00
我需要在 excel 文件中解析该字段以获取 37 作为 int。
我尝试了以下方法:
df['Planned working time'].map(lambda x: (x, x.split(":"))) gives me 'datetime.time' object has no attribute 'split'
df['Planned working time'].map(lambda x: datetime.datetime.strptime(str(x), "%H:%M:%S")) 给我的时间数据'1900-01-01 00:00:00' 与format '%H:%M:%S 不匹配
【问题讨论】:
-
'%H:%M:%S'对于您可能想要做的超过 24 小时的任何时间计算都是无用的,因此 1900 无关紧要;给它一年才有意义。您可以随时strftime将其返回到最后的时间戳。 -
如果是时间 stovfl 我同意这是相关的,但它不是时间字段。