Reputation: 346
I have a data table which consists of various columns including a date field which is in the form of (mm/dd/yy) as follows:
Now, how can I have to convert it to (yy/mm/dd) format?
I have used the following code:
d['Date'] = pd.to_datetime(d['Date'], format='%m/%d/%y')
But I am getting an error as follows:
ValueError: unconverted data remains: 05
Can someone please help me out with this? I know its relatively basic, but I am not able to get it.
Upvotes: 0
Views: 56
Reputation: 862591
I think there are some another format data, you can change them to NaT
:
#check them
print (d[pd.to_datetime(d['Date'], format='%m/%d/%y', errors='coerce').isna()])
d['Date'] = pd.to_datetime(d['Date'], format='%m/%d/%y', errors='coerce')
Upvotes: 3