I have a dataframe as follows:
ID Date_Loading Date_delivery Value
001 01.11.2017 20.11.2017 200.34
002 %^&**##_ 15.01.2018 300.05
003 11.12.2018 _%67* 7*7%
As we can see that except ID column I have special character in all columns.
Objective: To replace those special character by None. So the final dataframe should look like:
ID Date_Loading Date_delivery Value
001 01.11.2017 20.11.2017 200.34
002 Null 15.01.2018 300.05
003 11.12.2018 Null Null
Then as a next step I want parse the Date columns to YYYY-MM-DD format.
In order to accomplish this I am using the following code snippet:
for c in df.columns.tolist():
df[c] = df[c].astype(str).str.replace(r"[^A-Za-z0-9]"," ")
df['Date_Loading'] = pd.to_datetime(df['Date_Loading'],error='coerce',format='YYYY-MM-DD')
df['Date_delivery'] = pd.to_datetime(df['Date_Loading'],error='coerce',format='YYYY-MM-DD')
But the above code is just not working!!! Even if I am trying to replace, it is not working.
Am I missing out anything?
P.S.: I have tried in SO - > this and this but so far no luck
regex=Trueinstr.replacewill do the trick. But I need to convert the date fields as I wanted i.e.YYYY-MM-DDformat.But I need to convert the date fields as I wanted i.e. YYYY-MM-DD format.- Not sure if understand now not working?Valuefield as of now.