I have a dataframe that consists of separate columns for year, month and day. I tried to combine these individual columns into one date using:
df['myDt']=pd.to_datetime(df[['year','month','day']])
only to get the following error: "to assemble mappings requires at least that [year, month, day] be specified: [day,month,year] is missing". Not sure what this means....I'm already supplying the relevant columns. On checking the datatypes, I found that they Year, Month and Day columns are int64. Would that be causing an issue? Thanks, Chet
Thank you all for posting. As suggested, I'm posting the sample data set first:
Value mm yy dd
Date
2018-11-30 88.550067 11 2018 1
2018-12-31 88.906290 12 2018 1
2019-01-31 88.723000 1 2019 1
2019-02-28 89.509179 2 2019 1
2019-03-31 90.049161 3 2019 1
2019-04-30 90.523100 4 2019 1
2019-05-31 90.102484 5 2019 1
2019-06-30 91.179400 6 2019 1
2019-07-31 90.963570 7 2019 1
2019-08-31 92.159170 8 2019 1
The data source is:https://www.quandl.com/data/EIA/STEO_NGPRPUS_M I imported the data as follows: 1. import quandl (used conda install first) 2. Used Quandl's Python code:
data=quandl.get("EIA/STEO_NGPRPUS_M", authtoken="TOKEN","2005-01-01","2005-12-31") 4. Just to note, the original data comes only with the Value column, and DateTime as index. I extracted and created the mm,yy and dd columns (month, year, and dd is a column vector set to 1) All I'm trying to do is create another column called "first of the month" - so for each day of each month, the column will just show "MM/YY/1". I'm going to try out all the suggestions below shortly and get back to you guys. Thanks!!