0

train_df is as below:

application_date
2014-12-22
2015-11-29 and so on

train_df.dtypes

 application_date     object

Now, code I use to change the format of date from yyyy-mm-dd to mm/dd/yyyy is as below: '

     train_df['application_date'] = train_df['application_date'].apply(lambda x: datetime.strptime(x, 
     '%Y-%m-%d').strftime('%m/%d/%Y'))

If i again do train_df.dtypes, I am still getting application date as object

     application_date     object

If I type the below code to change application date to datetime, I get an error

train_df['application_date'] = train_df['application_date'].apply(lambda x: datetime.strptime(x, '%Y- 
%m-%d').strftime('%m/%d/%Y'))
train_df['application_date']=pd.to_datetime(train_df.application_date,'%m/%d/%Y')
noob
  • 3,601
  • 6
  • 27
  • 73
  • 1
    Did you post this question already? I remember seeing it earlier. – AMC Jan 18 '20 at 16:49
  • 1
    In any case, I will repeat exactly what I said then: That first `.apply(lambda)` is working exactly as expected. Your column contains strings, the lambda converts them to datetime objects, and then back to strings. You still haven't shared what the error you're getting is. – AMC Jan 18 '20 at 16:50
  • I don't think there really is much of question here, so I'm voting to close this. – AMC Jan 18 '20 at 16:51
  • Found the duplicate: https://stackoverflow.com/q/59801557/11301900. – AMC Jan 19 '20 at 03:01

0 Answers0