1

I'm trying to convert a column of my Pandas DataFrame that is in the format 09:18 PM to 21:18:00. It (sort of) worked with:

df['Time'] = pd.to_datetime(df['Time'], format="%I:%M %p")

But the output is, now:

df['Time']    
1900-01-01 21:18:00

I already have columns for Year, Month and Day, so I'd like to get back only H:M:S without 1900-01-01 included.

Any help is much appreciated.

HCSthe2nd
  • 175
  • 5
  • 16
  • Does it need to end up in datetime format, or can it just be a string? – Daniel Scott Jan 06 '19 at 01:36
  • time of day stored as datetime will always show a dummy date. You _should_ be able to ignore it for most operations, and you can specify a custom format when outputting the dataframe to a file or for display. – Haleemur Ali Jan 06 '19 at 01:38

1 Answers1

2

Using dt.time

df['Time']  = df['Time'].dt.time
BENY
  • 317,841
  • 20
  • 164
  • 234