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
Amit
  • 763
  • 1
  • 5
  • 14
  • 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 https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes. `time` doesn't offer as much options, but sometimes it's faster to use. – Night Train Jul 10 '20 at 09:06
  • Does this answer your question? [Convert Pandas Column to DateTime](https://stackoverflow.com/questions/26763344/convert-pandas-column-to-datetime) – Night Train Jul 10 '20 at 09:08

1 Answers1

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")
Nicolò Gasparini
  • 2,228
  • 2
  • 24
  • 53