Home > Blockchain >  How to convert this column into 12h format?
How to convert this column into 12h format?

Time:08-27

I have imported a dataset into a Pandas dataframe, but I can't quite figure out how I could convert the start time to a 12h clock (e.g. 4 pm)?

The variable columns are as follows:

start
2022-01-01 00:07:52.943
2022-01-01 00:09:31.745
2022-01-01 00:14:37.187

Thank you.

CodePudding user response:

You can use:

df['start'] = pd.to_datetime(df['start'])
df['start'] = df['start'].dt.date.astype(str)   ' '   df['start'].dt.strftime('%I:%M %p')

OUTPUT

                 start
0  2022-01-01 12:07 AM
1  2022-01-01 12:09 AM
2  2022-01-01 12:14 AM

CodePudding user response:

If dates are datetime values:

df.start.dt.strftime('%H%P')
  • Related