我的面板上满是股票数据,交易日不一致。您可以使用以下代码:数据帧.ix[dateSet]从pandas数据框中选择日期,但我想用panels做类似的事情,并在面板上循环并重新连接它们。所以某种程度上展板.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
.loc
支持多维选择,请参见here;这同样适用于.ix
和{相关问题 更多 >
编程相关推荐