python - How can I convert a series of integers into dates? -
i have pandas series of integers such as
151215
i want convert these integers in dates
2015-12-15
that means 15th december 2015. quick search on pandas websites suggests me use to_datetime() method. unfortunately realised if the pandas data string
st = '151215' pd.to_datetime(st)
then works correctly (except fact don't need time)
timestamp('2015-12-15 00:00:00')
but when pandas data integers
st = 151215 pd.to_datetime(st)
the result is
timestamp('1970-01-01 00:00:00.000151215')
could suggest me efficient way convert list of integers dates
you can use pandas.to_datetime no need convert string first (at least in pandas 0.19):
dates = pd.series([151215]*8) dates = pd.to_datetime(dates, format="%y%m%d") print(dates) 0 2015-12-15 1 2015-12-15 2 2015-12-15 3 2015-12-15 4 2015-12-15 5 2015-12-15 6 2015-12-15 7 2015-12-15 dtype: datetime64[ns]
converting single value in example result in timestamp('2015-12-15 00:00:00')
, if pass entire series result looks above.
Comments
Post a Comment