2012-12-23 3 views
2

2003 년 7 월 27 일부터 EURUSD 1 분 OHLC 데이터를 포함하는 312.5MB csv 파일이 있지만 날짜가 일광 절약 시간으로 조정되어 중복 및 간격이 있음을 의미합니다. 이 기본 날짜 파서가 너무 느렸다 같은 큰 파일, 그래서 이런 짓으로 보는Pandas read_csv 및 일광 절약 시간 제거

:

tizo = dateutil.tz.tzfile('/usr/share/zoneinfo/GB') 
def date_parse_1min(s): 
    return datetime(int(s[6:10]), 
        int(s[3:5]), 
        int(s[0:2]), 
        int(s[11:13]), 
        int(s[14:16]),tzinfo=tizo) 

df = read_csv("EURUSD_1m_clean_w_header.csv",index_col=0,parse_dates=True, date_parser=date_parse_1min) 

#verify that it's got the tz right: 
df.index 
Exception AttributeError: "'NoneType' object has no attribute 'toordinal'" in 'pandas.tslib._localize_tso' ignored 
Exception AttributeError: "'NoneType' object has no attribute 'toordinal'" in 'pandas.tslib._localize_tso' ignored 
<class 'pandas.tseries.index.DatetimeIndex'> 
[2003-07-26 23:00:00, ..., 2012-12-15 23:59:00] 
Length: 4938660, Freq: None, Timezone: tzfile('/usr/share/zoneinfo/GB') 

이 오류를 속성이 있습니다 왜 생각.

df.index.get_duplicates() 
<class 'pandas.tseries.index.DatetimeIndex'> 
[2003-10-26 01:00:00, ..., 2012-10-28 01:59:00] 
Length: 600, Freq: None, Timezone: None 
df1 = df.tz_convert('GMT') 
df1.index.get_duplicates() 
<class 'pandas.tseries.index.DatetimeIndex'> 
[2003-10-26 01:00:00, ..., 2012-10-28 01:59:00] 
Length: 600, Freq: None, Timezone: None 

일광 절약 시간제를 제거하려면 어떻게해야합니까? 분명히 나는 ​​변화가 필요한 올바른 정수 인덱스를 찾아 내고 그것을 할 수 있지만 더 좋은 방법이 있어야합니다.

+1

매분마다 'date_range'가되도록 색인을 설정할 수 있습니다. 그런 다음 차이점이 DST에서 한 시간 만 떨어져 있는지 확인하십시오. –

+0

데이터에서 누락 된 모든 분 (모든 주말 등)을 고려해야 만하지만 그와 비슷한 것을 할 수 있습니다. –

답변

0

각 연도의 첫 번째 및 마지막 중복 값을 가져 와서 한 시간 씩 데이터를 이동하면 가장 쉽게 문제를 해결할 수 있습니다. 처음 데이터 포인트가 일광 절약 시간부터 시작한다는 것은 분명히 고려해야합니다.

+0

첫날은 중복이 아니며 1 시간 간격입니다. 그러면 시계가 앞으로 나아갑니다. 나는 그것을 할 수는 있지만, 데이터에 존재하는 1 시간의 간격을 잠그는 것처럼 보이지는 않을 것이다. –