jmbejara / comp-econ-sp19

Main Course Repository for Computational Methods in Economics (Econ 21410, Spring 2019)
48 stars 26 forks source link

Convert int64 to datetime64-HW4 #40

Closed sicelyli closed 5 years ago

sicelyli commented 5 years ago

I'm having trouble converting the year column into datetime64[ns] I tried to_datetime couple times setting the unit differently, but seems like all of them set the year to 1970 Screen Shot 2019-05-05 at 11 53 09 PM Screen Shot 2019-05-05 at 11 53 17 PM

jmbejara commented 5 years ago

Take a look at the documentation for pd.to_datetime. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html

format : string, default None
    strftime to parse time, eg “%d/%m/%Y”, note that “%f” will parse all the way up to nanoseconds.

There are multiple ways to do this. One way is to use the format keyword argument. This accepts strings with symbols according to this reference: http://strftime.org/

sicelyli commented 5 years ago

Got it, thank you!