问题
I'm on pandas 0.14.1. Have two DataFrames both indexed by timezone-aware DatetimeIndex:
import pandas as pd
ix1 = pd.DatetimeIndex(start=pd.Timestamp('20140715', tz='EST5EDT'), end=pd.Timestamp('20140717', tz='EST5EDT'), freq='D', tz='EST5EDT')
ix2 = pd.DatetimeIndex([pd.Timestamp('2014-07-11 00:00:00', tz='EST5EDT'), pd.Timestamp('2014-07-21 00:00:00', tz='EST5EDT')])
df1 = pd.DataFrame(0, index=ix1, columns=['A', 'B'])
df2 = pd.DataFrame(0, index=ix2, columns=['A', 'B'])
Both indices having timezone, one with freq and one without:
df1.index
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-07-15 00:00:00-04:00, ..., 2014-07-17 00:00:00-04:00]
Length: 3, Freq: D, Timezone: EST5EDT
df2.index
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-07-11 00:00:00-04:00, 2014-07-21 00:00:00-04:00]
Length: 2, Freq: None, Timezone: EST5EDT
Then concatenating the two changes timezone to UTC
:
pd.concat([df1, df2]).index
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-07-15 04:00:00+00:00, ..., 2014-07-21 04:00:00+00:00]
Length: 5, Freq: None, Timezone: UTC
I wonder if this is a known bug or it has a particular reason.
来源:https://stackoverflow.com/questions/24830952/changing-timezone-on-pandas-datetimeindex-when-concatenating-dataframes-in-pytho