I am trying to convert timing data (lap times and sector times in motor racing) given in the format [ss.000 or m:ss.000] (se below) to seconds or datetime, in order to be able to analyse it.
df = pd.DataFrame([[48.004, 1:13.564], [38.965, 58.223], [45.630, 1:10.084]], columns=['S1', 'S2'])
What I would like to get is:
A B
0 48.004 73.564
1 38.965 58.223
2 45.630 70.084
The only way I was able to convert, is to split data first by '.' with str.split and then by ':'. Afterwards, I am converting minutes to seconds, add seconds and append milisesconds.
Is there any other more elegant way to convert to seconds?