Reputation: 523
I have a time column in mixed format, e.g. 19:30 and 8:00 pm. How do I assign it as a uniform time format, i.e. %H:%m or %H:%m %p?
df["Timestamp"].head(10)
0 10:00
1 10:30 AM
2 11:00
3 11:30 AM
4 12:00
5 12:30 PM
6 13:00
7 1:30 PM
8 14:00
9 14:30
Name: Timestamp, dtype: object
Upvotes: 2
Views: 8217
Reputation: 6784
You can use pandas parse_datetime
:
In [57]: pd.to_datetime(pd.Series(['10:00', '9:00 AM', '10:20 PM'])).apply(lambda x: x.strftime(r'%H:%M:%S'))
Out[57]:
0 10:00:00
1 09:00:00
2 22:20:00
Upvotes: 4