Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues converting from dtype ('O') to datetime

I'm importing a large number of text files and appending them to a pandas dataframe. There's a column with a bunch of dates I need, but I can't convert them to datetime because it's listed as an object. This line of code works for other any other dtype, but it throws an error when I run it here.

df['Date'] = pd.to_datetime(df['Date'], format='%m%d%y')

After running, it returns this error:

time data '01/07/2014' does not match format '%m%d%y' (match)
like image 980
JD2015 Avatar asked Sep 07 '25 20:09

JD2015


1 Answers

You can try add / twice and change y to Y:

pd.to_datetime(df['Date'], format='%m/%d/%Y')

See more info about formatting datetime in python.

like image 132
jezrael Avatar answered Sep 09 '25 17:09

jezrael