Bottom Page

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!
Quote
#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.
Quote
#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?
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Convert dataframe string column to numeric in Python darpInd 1 189 Mar-14-2020, 10:07 AM
Last Post: ndc85430
  Combine a number into integer column and preserv format as number zinho 2 174 Dec-23-2019, 05:02 PM
Last Post: zinho
  itertuples, new column, datetime, pandas karlito 6 463 Nov-29-2019, 11:07 AM
Last Post: karlito
  How to delete column if entire column values are "nan" Sri 4 873 Apr-13-2019, 12:16 PM
Last Post: Sri

Forum Jump:


Users browsing this thread: 1 Guest(s)