Python Forum
Convert df column to datetime format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert df column to datetime format
#1
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!
Reply
#2
You should pass date format parameter to pandas.to_datetime.

YYYY-mm-dd -> '%Y-%m-%d' -> format='%Y-%m-%d'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I convert time-series data in rows into column srvmig 0 2,035 Apr-11-2020, 05:40 AM
Last Post: srvmig
  Convert dataframe string column to numeric in Python darpInd 1 2,270 Mar-14-2020, 10:07 AM
Last Post: ndc85430
  Combine a number into integer column and preserv format as number zinho 2 1,881 Dec-23-2019, 05:02 PM
Last Post: zinho
  itertuples, new column, datetime, pandas karlito 6 3,888 Nov-29-2019, 11:07 AM
Last Post: karlito

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020