df['established_date']=[datetime.datetime.strptime(x,'%d-%m-%y').strftime("%y-%m-%d") if not x=="nan" else x for x in df.established_date]
I am not getting why it is not working.
or
I am trying to convert 12-07-17
this date fromat to 2017-07-12
this format.
I have written above code but it isn't working.
CodePudding user response:
There's a simpler method, that's designed for this, called pd.to_datetime
:
df.established_date = pd.to_datetime(df.established_date, errors='coerce').dt.strftime('%Y-%d-%m')