Reputation: 22041
gps nt_date
4002 20-Dec-16
4002 20-Dec-16
C-4 30-Jan-17
Y21-21 17-Nov-16
49a 22-Dec-16
In the dataframe above, how can I convert nt_date
column to pandas datetime? I am using this but it does not work:
pd.to_datetime(df['nt_date'], format='%d-%m-%Y')
How to fix this?
Upvotes: 1
Views: 49
Reputation: 51425
You're using slightly wrong directives. Try using %b
(Month as locale’s abbreviated name) and %y
(2 digit year, rather than %Y
which is 4 digit):
df['nt_date'] = pd.to_datetime(df['nt_date'], format='%d-%b-%y')
>>> df
gps nt_date
0 4002 2016-12-20
1 4002 2016-12-20
2 C-4 2017-01-30
3 Y21-21 2016-11-17
4 49a 2016-12-22
For more info, you can refer to these docs
Upvotes: 2