Reputation: 23
i have a column of time data taken that looks like that "Wed Aug 21 18:51:19 2019" im trying to convert it to dd/mm/yy with no successin order to sort by date with no luck.
thank you in advance
Upvotes: 0
Views: 230
Reputation: 4284
You need to find the right format to describe your string date.
Here it is '%a %b %d %H:%M:%S %Y'
because you start with %a
: abbreviated day of week, followed by a space then '%b'
: abbreviated day of month etc.
The complete list of available formats can be found here
import pandas as pd
import datetime as dt
df= pd.DataFrame({'date':["Wed Aug 21 18:51:19 2019"]})
# convert to datetime
df['new_datetime'] =pd.to_datetime(df['date'], format = '%a %b %d %H:%M:%S %Y')
# keep date part only
df['new_date'] =df['new_datetime'].dt.date
Upvotes: 2