2017-03-05 6 views
0

나는 다중 인덱스 팬더 배열을 가지고 있으며 9 : 30 ~ 10 : 00 사이에 최소값과 최대 값을 찾으려고합니다. 배열을 반복하고 시간이 일치하는지 검사 할 수 있습니다. 하지만 판다를 통한 방법이어야합니다 ...Python Pandas 여러 인덱스에서 시간별 검색

거래일 30 분을 그룹화/검색 할 수있는 방법이 있습니까? 그룹화하려고하는데 데이터가 사전 시장 가치가 있기 때문에 [: 30]을 사용하는 것이 좋지 않은 방식으로 제대로 작동하지 않습니다.

import pytz 
from datetime import datetime, date, time 
from datetime import timedelta 
import matplotlib.pyplot as pyplot 
from collections import defaultdict 
import pandas as pd 
from pandas.tseries.resample import TimeGrouper 
from pandas.tseries.offsets import DateOffset 
from pandas.tseries.index import DatetimeIndex 
from pandas import Timestamp 

def my_grouper(ts): 
    "Function to apply to the index of the DataFrame to break it into groups." 
    #pdb.set_trace() 
    # Returns midnight of the supplied date. 
    return pd.core.datetools.normalize_date(ts) 


def first_thirty_minutes(frame): 
    "Function to apply to the resulting groups." 
    start = frame.index.searchsorted("09:30:00") 
    end = frame.index.searchsorted("10:00:00") 
    return frame.iloc[start:end] 


hist = pd.read_csv("ES2.txt" ,index_col=0) 
eastern = pytz.timezone('US/Eastern') 
hist.index = pd.DatetimeIndex(hist.index).tz_localize('UTC').tz_convert('US/Eastern') 
data = hist.groupby(my_grouper).apply(first_thirty_minutes) 

데이터 :이 라인을 발견 한 더 굴착 후

DateTime,Hour,Open,High,Low,Close,Volume 
1997-09-11 00:00:00-04:00,1997-09-11 00:33:00-04:00,1176.25,1176.25,1174.5,1174.5,4 
1997-09-11 00:00:00-04:00,1997-09-11 00:34:00-04:00,1173.75,1173.75,1173.75,1173.75,1 
1997-09-11 00:00:00-04:00,1997-09-11 01:45:00-04:00,1173.25,1173.25,1173.25,1173.25,1 
1997-09-11 00:00:00-04:00,1997-09-11 04:08:00-04:00,1172.75,1172.75,1172.75,1172.75,1 
1997-09-11 00:00:00-04:00,1997-09-11 04:09:00-04:00,1172.5,1172.5,1172.5,1172.5,2 
1997-09-11 00:00:00-04:00,1997-09-11 04:10:00-04:00,1172.5,1172.5,1172.5,1172.5,1 
1997-09-11 00:00:00-04:00,1997-09-11 04:11:00-04:00,1172.0,1172.0,1172.0,1172.0,1 
1997-09-11 00:00:00-04:00,1997-09-11 04:20:00-04:00,1172.0,1172.0,1172.0,1172.0,1 
1997-09-11 00:00:00-04:00,1997-09-11 04:21:00-04:00,1171.75,1172.25,1171.75,1172.25,4 
1997-09-11 00:00:00-04:00,1997-09-11 04:22:00-04:00,1172.0,1172.0,1171.5,1171.5,2 
1997-09-11 00:00:00-04:00,1997-09-11 04:25:00-04:00,1171.0,1171.0,1171.0,1171.0,1 
1997-09-11 00:00:00-04:00,1997-09-11 04:31:00-04:00,1170.5,1170.5,1170.5,1170.5,1 
+0

http://pandas.pydata.org/pandas-docs/stable/merging.html#merging-asof –

답변

0

은 (between_time

복귀 frame.between_time

를 사용하여 ALGO 해결 얻는다 START_TIME = '9:30' end_time = '10 : 00 ')