0

I have a data frame of type str which I want to convert into DateTime format and then want to create another column for time only in hour: min :sec

   TimeStamp
  20200706 07:00:00
  20200706 08:07:00
  20200706 08:28:00
  20200706 09:30:00
  20200706 09:31:00
  20200706 09:32:00
2
  • Additionally to Nicolos answer: in general you can use the standard libraries datetime and time. in datetime you would use strftime() and strptime() to read and write specific formats docs.python.org/3/library/…. time doesn't offer as much options, but sometimes it's faster to use. Commented Jul 10, 2020 at 9:06
  • Does this answer your question? Convert Pandas Column to DateTime Commented Jul 10, 2020 at 9:08

1 Answer 1

2

to have it as timestamp

import pandas as pd
pd.to_datetime(df['Timestamp'])

To have another (string) column with hour, minutes and seconds

pd.to_datetime(df['Timestamp']).dt.strftime("%H:%M:%S")
Sign up to request clarification or add additional context in comments.

Comments

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.