标题说明了一切。我有一个日期/时间格式的字符串,我不知道如何将其转换为十进制。感谢
答案 0 :(得分:1)
import datetime
import re
timestr = '4 days, 23:56:46.063070'
matches = re.match('(\d+) days, (.*)', timestr)
assert matches
days = int(matches.group(1))
time = datetime.datetime.strptime(matches.group(2), '%H:%M:%S.%f')
timediff = time - datetime.datetime(1900, 1, 1) # timedelta
hours = days*24 + timediff.total_seconds()/60/60
顺便说一下119.946不是119.997。
答案 1 :(得分:0)
import pandas as pd
pd.Timedelta("4 days, 23:56:46.063070") / pd.Timedelta(1, 'h')
119.94612863055555