-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Description
I am confused by the dtype conversion function "astype" for pandas series. According to documentation, it should be the same as numpy.ndarray dtype conversion, but seems there is stil some difference. For example, if I try to convert columns of datetime type to object dtype, I got completely different results using astype function on pandas series versus on numpy array. My question is what sort of additional hanlding exists inside pandas Series dtype conversion? Example code as follows, note that pandas Series dtype conversion converts numpy.datetime64 to datetime.datetime, while numpy.array dtype conversion converts numpy.datetime64 to long. By the way, my numpy is version 1.8.0, and my pandas is version 0.12.0, and running on python 2.7.
import datetime
import numpy
import pandas
dd = pandas.DataFrame({"val": [datetime.datetime(2014, 1, 1, 9)]})
dd["val"].astype("object")
Out[1]:
0 2014-01-01 09:00:00
Name: val, dtype: object
numpy.array(dd["val"]).astype("object")
Out[1]: array([1388566800000000000L], dtype=object)