I am trying to extract the hour
from the column date in a 24-h
format.
It doesn't seem to work as I am only getting the AM
, from the following dataset:
Chicago crime
df["timestamp"] = pd.to_datetime(df["date"])
# Convert timestamp to AM/PM format
df["timestamp"] = df["timestamp"].apply(lambda x: x.strftime("%Y-%m-%d %I:%M:%S %p"))
df['hour'] = df['timestamp'].dt.hour
The hour
part is from 1-12, however, I don’t seem to have the AM/PM
, but only the UTC
in the time stamp.
Data in the time stamp column - date, is shown below;
date
-----------------------
2019-08-29 06:40:00 UTC
2010-03-07 01:21:00 UTC
2002-10-22 11:09:33 UTC
2012-02-20 09:00:00 UTC
2022-10-04 07:24:00 UTC
2005-09-28 04:00:00 UTC
2001-11-21 02:01:03 UTC
2021-01-24 01:00:00 UTC
2005-12-10 08:00:00 UTC
2011-10-18 04:00:00 UTC
2008-02-06 01:00:00 UTC
2001-07-30 03:36:18 UTC
2015-10-11 05:00:00 UTC
2010-02-04 10:15:00 UTC
2003-08-01 04:38:49 UTC