1

I have a pandas column with timestamp strings in the format '00:00:00.000' (hours, minutes, seconds, micro seconds). I would like to convert them to datetime objects to work on the seconds.

I have seen many similar questions here for example. I am guessing that I should use strptime but I couldn't figure out how.

ocns
  • 53
  • 6

1 Answers1

1

If convert values to datetimes in pandas, also there is added some default date by to_datetime:

df['col'] = pd.to_datetime(df['col'], format='%H:%M:%S.%f')

If need avoid it convert values to timedeltas by to_timedelta:

df['col'] = pd.to_timedelta(df['col'])
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252