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.

1 Answer 1

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'])
Sign up to request clarification or add additional context in comments.

1 Comment

@Ynjxsjmh - Ya, I know, explained more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.