Azure 云备份报告中的 Duration 列似乎有一个有趣的时间格式(小时后和分钟后为十进制)。你能帮忙把小时、分钟和秒部分四舍五入,使该列以小时为单位吗?
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
谢谢
largeQ
动漫人物
相关分类