import pandas as pd
index = pd.date_range("2015-01-01", "2015-10-1", freq="W-SUN")
s = pd.Series(index)
print index.dtype
print s.dtype
print index.tz_localize("utc").dtype
print s.dt.tz_localize("utc").dtype
here is the output:
datetime64[ns]
datetime64[ns]
datetime64[ns]
object
s.dt.tz_localize("utc")
is an array of Timestamp
objects instead of int64 with datetime64[ns]
dtype.
Here is show_versions()
output:
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.9.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
pandas: 0.16.2
nose: 1.3.4
Cython: 0.21.2
numpy: 1.9.1
scipy: 0.15.0
statsmodels: 0.6.1
IPython: 3.1.0
sphinx: 1.2.3
patsy: 0.3.0
dateutil: 2.3
pytz: 2014.10
bottleneck: None
tables: 3.1.1
numexpr: 2.4
matplotlib: 1.4.3
openpyxl: None
xlrd: 0.9.3
xlwt: None
xlsxwriter: 0.7.3
lxml: None
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 0.9.8
pymysql: None
psycopg2: None
Comment From: ruoyu0088
It seems that datetime columns can't have timezone information.
Comment From: jorisvandenbossche
Yes, the datetime64
numpy dtype doe snot support timezone information. For this reason, when the user explicitly wants such information in a series, it is converted to an object array of Timestamps (which can hold this information). This is a current limitation of numpy.
But note that there is undergoing work to have such support in pandas, see #10477