Vivek
Vivek

Reputation: 346

How to convert mm/dd/yy to yy/mm/dd using pandas in python?

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: enter image description here

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

Answers (1)

jezrael
jezrael

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

Related Questions