1
거래일 기준으로 정렬되지 않은 재고 데이터가있는 패널이 있습니다. code : dataFrame.ix [dateSet]을 사용하여 pandas DataFrame에서 날짜를 선택할 수 있지만 패널과 비슷한 작업을 수행하고 패널을 반복하고 다시 조인 할 수 있습니다. 그래서 일종의 Panel.ix [daterange]가 유용 할 것입니다.항목 반복으로 팬더 패널에서 날짜 선택
def slicePanelOverTradingDates(panel = fpStockPanel, security = 'SPY'):
# get the trading dates of the S&P starting with the first date of the panel's adjusted close item
validSPXDates = DataReader('SPY','yahoo',panel['Adj Close'].index[0].date()).index
# take the dates that are valid in the stock panel that intersect with the S&P's dates and makes sure they're in order
panelDatesOnSPXDays = list(set(panel['Adj Close'].index).intersection(set(validSPXDates)))
panelDatesOnSPXDays.sort()
# remakes the panel sliced only over the correct dates
panelFrame = {}
for x in panel.items:
panelFrame[x] = panel[x].ix[panelDatesOnSPXDays]
finalPanel = pd.Panel(panelFrame)
return finalPanel
위대한 작품입니다. 감사합니다. 원래 질문의 구문 사용 : tradingDates = DataReader ('SPY', 'yahoo', '2003-01-01') [ 'Adj Close']. dropna(). 인덱스 다음 d.loc [:, tradingDates] – goodalexander
다른 필드도 선택할 수 있습니다. ''panel.loc [items, major_axis, minor_axis]''; 항목 (또는 축)이 라벨 (목록 또는 idnexer가 아닌) 인 경우 결과의 크기가 삭제됩니다 (예 : 당신은 프레임을 얻을 것이다) – Jeff