如何使用python从timedelta变量中删除秒和微秒.我有以下数据框,我想删除秒.
df['Duration'] = ['03:12:37.771200','06:52:24.764500','13:19:57.325200','15:01:07.000200','04:05:06.722200','01:10:07.456200']
Run Code Online (Sandbox Code Playgroud)
使用round方法与'T'分钟
df['Duration'] = pd.to_timedelta(df['Duration']).round('T')
print(df)
Duration
0 03:13:00
1 06:52:00
2 13:20:00
3 15:01:00
4 04:05:00
5 01:10:00
Run Code Online (Sandbox Code Playgroud)
你也可以使用 floor
df['Duration'] = pd.to_timedelta(df['Duration']).floor('T')
print(df)
Duration
0 03:12:00
1 06:52:00
2 13:19:00
3 15:01:00
4 04:05:00
5 01:10:00
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
520 次 |
| 最近记录: |