I have such a column in a pandas dataframe:
duration
1 day 22:12:15.778543
2 days 10:09:07.118723
00:18:23.985112
I would like to convert this duration to seconds.
How can I do this? I am not sure if this is possible because of the special string format I got (1 day, 2 days etc.)?
>Solution :
Use to_timedelta with Series.dt.total_seconds:
df['s'] = pd.to_timedelta(df['duration']).dt.total_seconds()
print (df)
duration s
0 1 day 22:12:15.778543 166335.778543
1 2 days 10:09:07.118723 209347.118723
2 00:18:23.985112 1103.985112