Python Forum

Full Version: Convert df column to datetime format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I'm trying to convert a dataframe column to a datetime format using
pd.to_datetime(dataframe.column,infer_datetime_format=True)


The column contains some 2,000 dates formatted YYYY-mm-dd. However, when I pass the relevant column, I receive the following error:

ValueError: to assemble mappings requires at least that [year, month, day] be specified: [day,month,year] is missing

Is there something different I need to do in order to ensure the df column is formatted correctly before passing to the to_datetime function?

Thanks for any help, this is really frustrating me!
You should pass date format parameter to pandas.to_datetime.

YYYY-mm-dd -> '%Y-%m-%d' -> format='%Y-%m-%d'
(Oct-14-2019, 11:59 AM)perfringo Wrote: [ -> ]You should pass date format parameter to pandas.to_datetime.

YYYY-mm-dd -> '%Y-%m-%d' -> format='%Y-%m-%d'

Thanks, but I have tried it specifying these formats in a few different ways, and it continues to return the same error "ValueError: to assemble mappings requires at least that [year, month, day] be specified: [day,month,year] is missing"

The pandas.to_datetime documentation states that it should take an argument as 'integer, float, string, datetime, list, tuple, 1-d array, Series'. Does a df.column meet any of these definitions, or does it need to be converted into a Series or np.array or something first?