1

I have a series of strings representing time values in different formats - these are track meet running times in various events.

There are 3 time formats in my series. A sample looks like this:

Times
1:50.24
1:51.88
49.35
13:58.97
2:39:05

I need to do math with these - I think I need to convert them to timedeltas.

When I try: pd.to_timedelta(df['Times'])

I get

ValueError: expected hh:mm:ss format before .

Is there a way to easily convert these strings into a common time datatype that I can do arithmetic with?

Backle
  • 11
  • 2
  • Might need to build a function like the following that deals with each case https://stackoverflow.com/questions/23581128/how-to-format-date-string-via-multiple-formats-in-python – le_camerone Jul 23 '21 at 03:48
  • Thanks for the link @le_camerone - I was wondering if this could be done more directly than having to deal with each case separately - but your link put me onto dateutil.parser which is helpful! – Backle Jul 23 '21 at 11:52

0 Answers0