在Python中连接数据帧时更改DatetimeIndex上的时区

在Python中连接数据帧时更改DatetimeIndex上的时区,python,pandas,timestamp,timestamp-with-timezone,Python,Pandas,Timestamp,Timestamp With Timezone,我在熊猫0.14.1上。有两个数据帧都由时区感知的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

我在熊猫0.14.1上。有两个数据帧都由时区感知的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'])
两个索引都有时区,一个带freq,另一个不带:

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

我想知道这是一个已知的错误还是有特定的原因。

这是一个错误。需要一些代码来确定是否重新创建tz(例如,它必须在所有片段上,并且它们必须相同)。我认为只要两者的长度都大于2(这是因为len(2)的索引不能有一个推断的_freq,只能有一个设置的freq)。在我的代码中有我自己的concat版本,我就是这样做的。虽然这可能有助于显示错误,或找到原因。。。谢谢你的快速回复!是的,它实际上大部分时间都有效,很难创建示例。问题是:,欢迎拉取请求!
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