Azure云备份报告中的持续时间列似乎有一个有趣的时间格式(小时和分钟后的小数)。你能帮我把小时、分钟和秒的部分改成小时吗
1.05:27:39.9470724
21:17.7
21:41.4
1.02:42:37.1136811
21:17.2
我试图格式化微秒部分,但不确定如何处理小时部分的小数。很高兴排除这些小数
appended_data['Duration'] = pd.to_datetime(appended_data['Duration'], format='%H:%M:%S.%f')
ValueError: time data '1.05:27:39.9470724' does not match format '%H:%M:%S.%f' (match)
appended_data['Backup Size'] = appended_data['Backup Size'].str.replace('MB','')
appended_data['DurationFixed'] = pd.to_timedelta(df['Duration'].str.split(':',expand=True)\
.stack()\
.astype(float)\
.round()\
.astype(int).astype(str).unstack(1).fillna('00').agg(':'.join,axis=1),
unit='s')
appended_data['DurationHours'] = appended_data['DurationFixed'] / np.timedelta64(1,'h')
appended_data['Duration']
1 04:01:22.7756139
1 03:31:17.0678262
1 04:41:32.7253765
1 03:11:18.3396588
1 04:51:20.2017034
...
1 02:21:17.8554095
1 02:21:19.5547075
1 03:41:23.8876812
1 02:21:32.5529160
1 02:01:20.3247238
appended_data['DurationFixed']
1 02:01:20
1 02:01:20
1 02:01:20
1 02:01:20
1 02:01:20
...
1 02:01:20
1 02:01:20
1 02:01:20
1 02:01:20
1 02:01:20
谢谢
嗯
这似乎是一个奇怪的错误,因为我从未见过azure中有这样的日志——不管怎样,除非有某种内置方法来处理这样的数据,否则我们需要手动解析它
我们将按
:
进行拆分,然后在重新创建时间增量字符串之前对数字进行四舍五入我必须清楚地说,这不是一个真正的修复,因为你需要限定
1.05
是什么,是1小时x分钟吗如果你不在乎上面的,那么下面的就行了
方法1无精度,字符串格式
如果您只需要几个小时,您可以使用
np.timedelta64
转换它方法2更精确
如果您的数据格式相同-即
Hours : Minutes : Seconds
我们可以堆叠并应用累积计数和映射元数据字段,以便在行级别使用我们的
pd.to_timedelta
最后,我们在行级别使用
apply
将每一行转换为其代表格式,并四舍五入到最接近的n
秒。我选了10个根据对数据的分析,我可以得出结论,hh部分的小数位实际上是天。示例2.4:30:30=2天4小时30分钟30秒
相关问题 更多 >
编程相关推荐