I need to transform "Jan 11, 2017 9:00 PM" to 2017-01-11 21:00:00 for all values in ColumnA.
Is there an easy way / function for doing this in python using pandas?
to_datetime
seems to handle this just fine:
In [6]:
pd.to_datetime('Jan 11, 2017 9:00 PM')
Out[6]:
Timestamp('2017-01-11 21:00:00')
So you can just overwrite your column using the output from this function:
df['ColumnA'] = pd.to_datetime(df['ColumnA'])
And just to clarify that the dates and months are correct here:
In [8]:
pd.to_datetime('Jan 11, 2017 9:00 PM').day
Out[8]:
11
In [9]:
pd.to_datetime('Jan 11, 2017 9:00 PM').month
Out[9]:
1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.