【发布时间】:2021-06-26 01:55:27
【问题描述】:
我有一个带有duration 字符串列的数据框,格式如下:
| index | duration |
|---|---|
| 0 | 26 s |
| 1 | 24 s |
| 2 | 4 min, 37 s |
| 3 | 7 s |
| 4 | 1 min, 1 s |
是否有 pandas 或 strftime() / strptime() 方法可以将 duration 列转换为分钟/秒时间戳。
我尝试过这种方式来转换字符串,但是替换字符串后会遇到多种情况:
for row in df['index']:
if "min, " in df['duration'][row]:
df['duration'][row] = df['duration'][row].replace(' min, ', ':').replace(' s', '')
else:
pass
提前致谢
【问题讨论】:
标签: python pandas timestamp timedelta