从日志中转换 hours:minutes:seconds 的特定时间戳并将其仅转换为秒
Converting a specific time stamp of hours:minutes:seconds from a log and turning it into seconds only
所以我从 csv 文件中获取值 a2 和 a3,为了写出我的等式,我需要以秒为单位的值 a4 而不是 hours:minutes:seconds,目前显示为 0:01:01 (61 秒)当我打印 a4.
a2 = tow3.loc[38, 'TimeString']
a2 = datetime.strptime(a2, '%d-%b-%Y %H:%M:%S')
print(a2.strftime('%M:%S'))
a3 = tow3.loc[98, 'TimeString']
a3 = datetime.strptime(a3, '%d-%b-%Y %H:%M:%S')
print(a3.strftime('%M:%S'))
a4 = a3-a2
print(a4)
My current execution
使用:
d1 = pd.date_range('05-12-2021', '06-12-2021', 10)
d2 = pd.date_range('06-12-2021', '07-12-2021', 10)
(d2-d1).seconds
输出:
Int64Index([0, 76800, 67200, 57600, 48000, 38400, 28800, 19200, 9600, 0], dtype='int64')
如果 (a3-a2) 是 datetime.timedelta 类型,那么您可以使用
(a3-a2).total_seconds()
将整个时间差转换为秒
所以我从 csv 文件中获取值 a2 和 a3,为了写出我的等式,我需要以秒为单位的值 a4 而不是 hours:minutes:seconds,目前显示为 0:01:01 (61 秒)当我打印 a4.
a2 = tow3.loc[38, 'TimeString']
a2 = datetime.strptime(a2, '%d-%b-%Y %H:%M:%S')
print(a2.strftime('%M:%S'))
a3 = tow3.loc[98, 'TimeString']
a3 = datetime.strptime(a3, '%d-%b-%Y %H:%M:%S')
print(a3.strftime('%M:%S'))
a4 = a3-a2
print(a4)
My current execution
使用:
d1 = pd.date_range('05-12-2021', '06-12-2021', 10)
d2 = pd.date_range('06-12-2021', '07-12-2021', 10)
(d2-d1).seconds
输出:
Int64Index([0, 76800, 67200, 57600, 48000, 38400, 28800, 19200, 9600, 0], dtype='int64')
如果 (a3-a2) 是 datetime.timedelta 类型,那么您可以使用
(a3-a2).total_seconds()
将整个时间差转换为秒