1
  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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.