Pandas Time Zone Aware Index Drops Time Zone When Converting to Series

I am trying to get the data frame time index as a series, but it seems to drop the timezone when I call the to_series method. The following is an example. Is this a mistake or am I doing something wrong?

rows = 50
df = pd.DataFrame(np.random.randn(rows,2), columns=list('AB'), index=pd.date_range('1/1/2000', periods=rows, freq='1H', tz=pytz.UTC))

print df.index[-1]
# 2000-01-03 01:00:00+00:00

print df.index.to_series()[-1]
# 2000-01-03 01:00:00


print df.index[-1].tzinfo
# UTC

print df.index.to_series()[-1].tzinfo
#None
+4
source share
1 answer

, - , .
pandas/numpy: , , . numpy datetime64 , . : https://github.com/pydata/pandas/issues/8260

, object dtype datetime64 ( Timestamp, datetime.datetime). .
to_series keep_tz (. docstring):

In [34]: df = df.tz_convert('US/Eastern')

In [35]: df.index.to_series()[-1]
Out[35]: Timestamp('2000-01-03 01:00:00')

In [36]: df.index.to_series(keep_tz=True)[-1]
Out[36]: Timestamp('2000-01-02 20:00:00-0500', tz='US/Eastern', offset='H')
+2

All Articles