在Python中连接DataFrame时,在pandas DatetimeIndex上更改时区

时间:2014-07-18 17:48:30

标签: python pandas timestamp timestamp-with-timezone

我对熊猫0.14.1。有两个DataFrame都由时区感知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

然后将两个更改时区连接到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

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

0 个答案:

没有答案