2016-09-08 4 views
3

나는 Tz-aware TimeStamp 인 열을 가진 Pandas DataFrame을 가지고 있으며 groupby (level = 0) .first()를 시도했습니다. 잘못된 결과가 나옵니다. 내가 뭔가를 놓치고 있거나 팬더 버그입니까?Pandas groupby datatime index, possible bug

x = pd.DataFrame(index = [1,1,2,2,2], data = pd.date_range("7:00", "9:00", freq="30min", tz = 'US/Eastern')) 

In [58]: x 
Out[58]: 


    0 
1 2016-09-08 07:00:00-04:00 
1 2016-09-08 07:30:00-04:00 
2 2016-09-08 08:00:00-04:00 
2 2016-09-08 08:30:00-04:00 
2 2016-09-08 09:00:00-04:00 

In [59]: x.groupby(level=0).first() 
Out[59]: 
          0 
1 2016-09-08 11:00:00-04:00 
2 2016-09-08 12:00:00-04:00 
+2

그것은 벌레처럼 보이는 ... 팬더는 UTC에 타임 스탬프를 변환하지만, 그것은 또한 오래된 TZ 정보를 보존합니다 ... – MaxU

+0

확실히 버그입니다. – piRSquared

답변

2

나는 버그라고 생각하지 않습니다. pytz 문서를 살펴보면 미국/동부 표준 시간대의 경우 일광 절약 시간제 전환 전/후에 지정할 방법이 없음이 분명하게 표시됩니다.

그런 경우 UTC를 고집하는 것이 가장 좋은 방법 인 것 같습니다. docs에서

발췌 : 변환과 같이 수행 할 수 있습니다

Be aware that timezones (e.g., pytz.timezone('US/Eastern')) are not 
necessarily equal across timezone versions. So if data is localized to 
a specific timezone in the HDFStore using one version of a timezone 
library and that data is updated with another version, the data will 
be converted to UTC since these timezones are not considered equal. 
Either use the same version of timezone library or use tz_convert with 
the updated timezone definition. 

은 다음과 같습니다

A : 순진/시간 인식 UTC

에 날짜를 지역화 tz_localize 방법을 사용하여
data = pd.date_range("7:00", "9:00", freq="30min").tz_localize('UTC') 

B :tz_convert을 사용하여 팬더 개체를 변환하여 tz 인식 데이터를 다른 시간대로 변환하는 방법. 결과

df = pd.DataFrame(index=[1,1,2,2,2], data=data.tz_convert('US/Eastern')) 
df.groupby(level=0).first() 

가 :

      0 
1 2016-09-09 07:00:00-04:00 
2 2016-09-09 08:00:00-04:00 

#0 datetime64[ns, US/Eastern] 
#dtype: object 
관련 문제