简体   繁体   English

从多索引DataFrame检索切片

[英]Retrieving a slice from a multiindexed DataFrame

I have a Pandas DataFrame with MultiIndex such as follow: 我有一个带有MultiIndex的Pandas DataFrame,如下所示:

在此处输入图片说明

I am trying to retrieve few rows using a IndexSlice: 我正在尝试使用IndexSlice检索几行:

idx=pd.IndexSlice
prices.loc[idx[["2016-09-19 13:30:00":"2016-09-19 14:30:00"],"Chinese Renminbioffshore"],:]

But i receive error: 但我收到错误:

SyntaxError: invalid syntax

According to the documentation (scroll to in:72) , I should be able to do that. 根据文档(滚动到in:72) ,我应该能够做到这一点。

Anyone has a suggestion? 有人有建议吗?

Here the data to recreate the dataframe: 此处的数据用于重新创建数据框:

EDIT: it seems that i cannot post the data to recreate this dataframe as it makes the proportion of the question looking like code is too great for SO... Hopefully this problem is still resolvable. 编辑:似乎我无法发布数据来重新创建此数据框,因为它使问题的比例看起来像代码对于SO而言太大...希望此问题仍可解决。

EDIT2: Maybe posting it like so would be helpful? EDIT2:也许像这样发布它会有所帮助吗?

{'ID': {(Timestamp('2016-09-19 13:30:00'), '10 Year US Treasury Note'): 6211,
  (Timestamp('2016-09-19 13:30:00'), '30 Day Fed Funds'): 37585,
  (Timestamp('2016-09-19 13:30:00'), 'Bloomberg Commodity Index'): 3757,
  (Timestamp('2016-09-19 13:30:00'), 'E-mini S&P 500'): 1,
  (Timestamp('2016-09-19 13:30:00'), 'Gold'): 33824,
  (Timestamp('2016-09-19 13:30:00'), 'Henry Hub Natural Gas'): 41328,
  (Timestamp('2016-09-19 13:30:00'), 'Lean Hogs'): 9971,
  (Timestamp('2016-09-19 13:30:00'), 'Light Sweet Crude Oil'): 45089,
  (Timestamp('2016-09-19 13:30:00'), 'Live Cattle'): 21274,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Copper Index'): 30063,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Palladium Index'): 17513,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Platinum Index'): 26302,
  (Timestamp('2016-09-19 13:30:00'), 'Soybean Meal Futures'): 23788,
  (Timestamp('2016-09-19 13:30:00'), 'Soybean Oil Futures'): 14999,
  (Timestamp('2016-09-19 13:30:00'), 'Wheat Futures'): 12485,
  (Timestamp('2016-09-19 14:00:00'), '10 Year US Treasury Note'): 6212,
  (Timestamp('2016-09-19 14:00:00'), '30 Day Fed Funds'): 37586,
  (Timestamp('2016-09-19 14:00:00'), 'Bloomberg Commodity Index'): 3758,
  (Timestamp('2016-09-19 14:00:00'), 'E-mini S&P 500'): 2,
  (Timestamp('2016-09-19 14:00:00'), 'Gold'): 33825,
  (Timestamp('2016-09-19 14:00:00'), 'Henry Hub Natural Gas'): 41329,
  (Timestamp('2016-09-19 14:00:00'), 'Lean Hogs'): 9972,
  (Timestamp('2016-09-19 14:00:00'), 'Light Sweet Crude Oil'): 45090,
  (Timestamp('2016-09-19 14:00:00'), 'Live Cattle'): 21275,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Copper Index'): 30064,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Palladium Index'): 17514,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Platinum Index'): 26303,
  (Timestamp('2016-09-19 14:00:00'), 'Soybean Meal Futures'): 23789,
  (Timestamp('2016-09-19 14:00:00'), 'Soybean Oil Futures'): 15000,
  (Timestamp('2016-09-19 14:00:00'), 'Wheat Futures'): 12486,
  (Timestamp('2016-09-19 14:30:00'), '10 Year US Treasury Note'): 6213,
  (Timestamp('2016-09-19 14:30:00'), '30 Day Fed Funds'): 37587,
  (Timestamp('2016-09-19 14:30:00'), 'Bloomberg Commodity Index'): 3759,
  (Timestamp('2016-09-19 14:30:00'), 'E-mini S&P 500'): 3,
  (Timestamp('2016-09-19 14:30:00'), 'Gold'): 33826,
  (Timestamp('2016-09-19 14:30:00'), 'Henry Hub Natural Gas'): 41330,
  (Timestamp('2016-09-19 14:30:00'), 'Lean Hogs'): 9973,
  (Timestamp('2016-09-19 14:30:00'), 'Light Sweet Crude Oil'): 45091,
  (Timestamp('2016-09-19 14:30:00'), 'Live Cattle'): 21276,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Copper Index'): 30065,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Palladium Index'): 17515,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Platinum Index'): 26304,
  (Timestamp('2016-09-19 14:30:00'), 'Soybean Meal Futures'): 23790,
  (Timestamp('2016-09-19 14:30:00'), 'Soybean Oil Futures'): 15001,
  (Timestamp('2016-09-19 14:30:00'), 'Wheat Futures'): 12487,
  (Timestamp('2016-09-19 15:00:00'), '10 Year US Treasury Note'): 6214,
  (Timestamp('2016-09-19 15:00:00'), '30 Day Fed Funds'): 37588,
  (Timestamp('2016-09-19 15:00:00'), 'Bloomberg Commodity Index'): 3760,
  (Timestamp('2016-09-19 15:00:00'), 'E-mini S&P 500'): 4,
  (Timestamp('2016-09-19 15:00:00'), 'Gold'): 33827},
 'close': {(Timestamp('2016-09-19 13:30:00'),
   '10 Year US Treasury Note'): 128.671875,
  (Timestamp('2016-09-19 13:30:00'), '30 Day Fed Funds'): 98.879999999999995,
  (Timestamp('2016-09-19 13:30:00'),
   'Bloomberg Commodity Index'): 84.900000000000006,
  (Timestamp('2016-09-19 13:30:00'), 'E-mini S&P 500'): 2132.0,
  (Timestamp('2016-09-19 13:30:00'), 'Gold'): 1339.4000000000001,
  (Timestamp('2016-09-19 13:30:00'),
   'Henry Hub Natural Gas'): 4.8360000000000003,
  (Timestamp('2016-09-19 13:30:00'), 'Lean Hogs'): 55.774999999999999,
  (Timestamp('2016-09-19 13:30:00'),
   'Light Sweet Crude Oil'): 49.420000000000002,
  (Timestamp('2016-09-19 13:30:00'), 'Live Cattle'): 97.224999999999994,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Copper Index'): 2.2149999999999999,
  (Timestamp('2016-09-19 13:30:00'),
   'NYMEX Palladium Index'): 684.29999999999995,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Platinum Index'): 1036.0,
  (Timestamp('2016-09-19 13:30:00'),
   'Soybean Meal Futures'): 336.30000000000001,
  (Timestamp('2016-09-19 13:30:00'),
   'Soybean Oil Futures'): 34.460000000000001,
  (Timestamp('2016-09-19 13:30:00'), 'Wheat Futures'): 497.0,
  (Timestamp('2016-09-19 14:00:00'), '10 Year US Treasury Note'): 128.609375,
  (Timestamp('2016-09-19 14:00:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 14:00:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 14:00:00'), 'E-mini S&P 500'): 2131.0,
  (Timestamp('2016-09-19 14:00:00'), 'Gold'): 1339.0999999999999,
  (Timestamp('2016-09-19 14:00:00'),
   'Henry Hub Natural Gas'): 4.8179999999999996,
  (Timestamp('2016-09-19 14:00:00'), 'Lean Hogs'): 55.174999999999997,
  (Timestamp('2016-09-19 14:00:00'),
   'Light Sweet Crude Oil'): 49.719999999999999,
  (Timestamp('2016-09-19 14:00:00'), 'Live Cattle'): 97.275000000000006,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Copper Index'): 2.2145000000000001,
  (Timestamp('2016-09-19 14:00:00'),
   'NYMEX Palladium Index'): 692.39999999999998,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Platinum Index'): 1039.0,
  (Timestamp('2016-09-19 14:00:00'), 'Soybean Meal Futures'): 335.0,
  (Timestamp('2016-09-19 14:00:00'), 'Soybean Oil Futures'): 34.5,
  (Timestamp('2016-09-19 14:00:00'), 'Wheat Futures'): 494.25,
  (Timestamp('2016-09-19 14:30:00'), '10 Year US Treasury Note'): 128.609375,
  (Timestamp('2016-09-19 14:30:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 14:30:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 14:30:00'), 'E-mini S&P 500'): 2128.0,
  (Timestamp('2016-09-19 14:30:00'), 'Gold'): 1338.2,
  (Timestamp('2016-09-19 14:30:00'),
   'Henry Hub Natural Gas'): 4.8179999999999996,
  (Timestamp('2016-09-19 14:30:00'), 'Lean Hogs'): 55.024999999999999,
  (Timestamp('2016-09-19 14:30:00'),
   'Light Sweet Crude Oil'): 49.689999999999998,
  (Timestamp('2016-09-19 14:30:00'), 'Live Cattle'): 97.125,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Copper Index'): 2.2145000000000001,
  (Timestamp('2016-09-19 14:30:00'),
   'NYMEX Palladium Index'): 688.79999999999995,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Platinum Index'): 1040.0,
  (Timestamp('2016-09-19 14:30:00'),
   'Soybean Meal Futures'): 333.19999999999999,
  (Timestamp('2016-09-19 14:30:00'),
   'Soybean Oil Futures'): 34.530000000000001,
  (Timestamp('2016-09-19 14:30:00'), 'Wheat Futures'): 491.25,
  (Timestamp('2016-09-19 15:00:00'), '10 Year US Treasury Note'): 128.640625,
  (Timestamp('2016-09-19 15:00:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 15:00:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 15:00:00'), 'E-mini S&P 500'): 2129.0,
  (Timestamp('2016-09-19 15:00:00'), 'Gold'): 1338.2},
 'high': {(Timestamp('2016-09-19 13:30:00'),
   '10 Year US Treasury Note'): 128.703125,
  (Timestamp('2016-09-19 13:30:00'), '30 Day Fed Funds'): 98.879999999999995,
  (Timestamp('2016-09-19 13:30:00'),
   'Bloomberg Commodity Index'): 84.900000000000006,
  (Timestamp('2016-09-19 13:30:00'), 'E-mini S&P 500'): 2133.0,
  (Timestamp('2016-09-19 13:30:00'), 'Gold'): 1341.2,
  (Timestamp('2016-09-19 13:30:00'),
   'Henry Hub Natural Gas'): 4.8529999999999998,
  (Timestamp('2016-09-19 13:30:00'), 'Lean Hogs'): 56.149999999999999,
  (Timestamp('2016-09-19 13:30:00'), 'Light Sweet Crude Oil'): 49.5,
  (Timestamp('2016-09-19 13:30:00'), 'Live Cattle'): 97.724999999999994,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Copper Index'): 2.2200000000000002,
  (Timestamp('2016-09-19 13:30:00'),
   'NYMEX Palladium Index'): 684.79999999999995,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Platinum Index'): 1039.0,
  (Timestamp('2016-09-19 13:30:00'),
   'Soybean Meal Futures'): 339.30000000000001,
  (Timestamp('2016-09-19 13:30:00'),
   'Soybean Oil Futures'): 34.469999999999999,
  (Timestamp('2016-09-19 13:30:00'), 'Wheat Futures'): 498.25,
  (Timestamp('2016-09-19 14:00:00'), '10 Year US Treasury Note'): 128.71875,
  (Timestamp('2016-09-19 14:00:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 14:00:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 14:00:00'), 'E-mini S&P 500'): 2134.0,
  (Timestamp('2016-09-19 14:00:00'), 'Gold'): 1340.2,
  (Timestamp('2016-09-19 14:00:00'),
   'Henry Hub Natural Gas'): 4.8410000000000002,
  (Timestamp('2016-09-19 14:00:00'), 'Lean Hogs'): 55.774999999999999,
  (Timestamp('2016-09-19 14:00:00'),
   'Light Sweet Crude Oil'): 49.920000000000002,
  (Timestamp('2016-09-19 14:00:00'), 'Live Cattle'): 97.400000000000006,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Copper Index'): 2.2164999999999999,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Palladium Index'): 693.75,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Platinum Index'): 1041.0,
  (Timestamp('2016-09-19 14:00:00'), 'Soybean Meal Futures'): 336.5,
  (Timestamp('2016-09-19 14:00:00'),
   'Soybean Oil Futures'): 34.609999999999999,
  (Timestamp('2016-09-19 14:00:00'), 'Wheat Futures'): 497.25,
  (Timestamp('2016-09-19 14:30:00'), '10 Year US Treasury Note'): 128.640625,
  (Timestamp('2016-09-19 14:30:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 14:30:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 14:30:00'), 'E-mini S&P 500'): 2131.0,
  (Timestamp('2016-09-19 14:30:00'), 'Gold'): 1339.7,
  (Timestamp('2016-09-19 14:30:00'),
   'Henry Hub Natural Gas'): 4.8220000000000001,
  (Timestamp('2016-09-19 14:30:00'), 'Lean Hogs'): 55.375,
  (Timestamp('2016-09-19 14:30:00'),
   'Light Sweet Crude Oil'): 49.880000000000003,
  (Timestamp('2016-09-19 14:30:00'), 'Live Cattle'): 97.200000000000003,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Copper Index'): 2.2155,
  (Timestamp('2016-09-19 14:30:00'),
   'NYMEX Palladium Index'): 692.79999999999995,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Platinum Index'): 1041.0,
  (Timestamp('2016-09-19 14:30:00'), 'Soybean Meal Futures'): 335.0,
  (Timestamp('2016-09-19 14:30:00'), 'Soybean Oil Futures'): 34.57,
  (Timestamp('2016-09-19 14:30:00'), 'Wheat Futures'): 494.5,
  (Timestamp('2016-09-19 15:00:00'), '10 Year US Treasury Note'): 128.65625,
  (Timestamp('2016-09-19 15:00:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 15:00:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 15:00:00'), 'E-mini S&P 500'): 2130.0,
  (Timestamp('2016-09-19 15:00:00'), 'Gold'): 1338.8},
 'low': {(Timestamp('2016-09-19 13:30:00'),
   '10 Year US Treasury Note'): 128.625,
  (Timestamp('2016-09-19 13:30:00'), '30 Day Fed Funds'): 98.879999999999995,
  (Timestamp('2016-09-19 13:30:00'),
   'Bloomberg Commodity Index'): 84.900000000000006,
  (Timestamp('2016-09-19 13:30:00'), 'E-mini S&P 500'): 2125.0,
  (Timestamp('2016-09-19 13:30:00'), 'Gold'): 1338.7,
  (Timestamp('2016-09-19 13:30:00'),
   'Henry Hub Natural Gas'): 4.8029999999999999,
  (Timestamp('2016-09-19 13:30:00'), 'Lean Hogs'): 55.100000000000001,
  (Timestamp('2016-09-19 13:30:00'),
   'Light Sweet Crude Oil'): 49.039999999999999,
  (Timestamp('2016-09-19 13:30:00'), 'Live Cattle'): 96.900000000000006,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Copper Index'): 2.2134999999999998,
  (Timestamp('2016-09-19 13:30:00'),
   'NYMEX Palladium Index'): 681.79999999999995,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Platinum Index'): 1034.0,
  (Timestamp('2016-09-19 13:30:00'),
   'Soybean Meal Futures'): 336.10000000000002,
  (Timestamp('2016-09-19 13:30:00'),
   'Soybean Oil Futures'): 34.270000000000003,
  (Timestamp('2016-09-19 13:30:00'), 'Wheat Futures'): 493.25,
  (Timestamp('2016-09-19 14:00:00'), '10 Year US Treasury Note'): 128.59375,
  (Timestamp('2016-09-19 14:00:00'), '30 Day Fed Funds'): 98.879999999999995,
  (Timestamp('2016-09-19 14:00:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 14:00:00'), 'E-mini S&P 500'): 2130.0,
  (Timestamp('2016-09-19 14:00:00'), 'Gold'): 1338.5999999999999,
  (Timestamp('2016-09-19 14:00:00'),
   'Henry Hub Natural Gas'): 4.8129999999999997,
  (Timestamp('2016-09-19 14:00:00'), 'Lean Hogs'): 55.125,
  (Timestamp('2016-09-19 14:00:00'),
   'Light Sweet Crude Oil'): 49.240000000000002,
  (Timestamp('2016-09-19 14:00:00'), 'Live Cattle'): 96.849999999999994,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Copper Index'): 2.2094999999999998,
  (Timestamp('2016-09-19 14:00:00'),
   'NYMEX Palladium Index'): 683.85000000000002,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Platinum Index'): 1036.0,
  (Timestamp('2016-09-19 14:00:00'),
   'Soybean Meal Futures'): 334.69999999999999,
  (Timestamp('2016-09-19 14:00:00'),
   'Soybean Oil Futures'): 34.450000000000003,
  (Timestamp('2016-09-19 14:00:00'), 'Wheat Futures'): 494.25,
  (Timestamp('2016-09-19 14:30:00'), '10 Year US Treasury Note'): 128.546875,
  (Timestamp('2016-09-19 14:30:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 14:30:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 14:30:00'), 'E-mini S&P 500'): 2127.0,
  (Timestamp('2016-09-19 14:30:00'), 'Gold'): 1337.5999999999999,
  (Timestamp('2016-09-19 14:30:00'),
   'Henry Hub Natural Gas'): 4.8019999999999996,
  (Timestamp('2016-09-19 14:30:00'), 'Lean Hogs'): 54.875,
  (Timestamp('2016-09-19 14:30:00'),
   'Light Sweet Crude Oil'): 49.560000000000002,
  (Timestamp('2016-09-19 14:30:00'), 'Live Cattle'): 96.799999999999997,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Copper Index'): 2.2134999999999998,
  (Timestamp('2016-09-19 14:30:00'),
   'NYMEX Palladium Index'): 688.60000000000002,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Platinum Index'): 1039.0,
  (Timestamp('2016-09-19 14:30:00'), 'Soybean Meal Futures'): 333.0,
  (Timestamp('2016-09-19 14:30:00'),
   'Soybean Oil Futures'): 34.479999999999997,
  (Timestamp('2016-09-19 14:30:00'), 'Wheat Futures'): 490.25,
  (Timestamp('2016-09-19 15:00:00'), '10 Year US Treasury Note'): 128.59375,
  (Timestamp('2016-09-19 15:00:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 15:00:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 15:00:00'), 'E-mini S&P 500'): 2127.0,
  (Timestamp('2016-09-19 15:00:00'), 'Gold'): 1337.7},
 'open': {(Timestamp('2016-09-19 13:30:00'),
   '10 Year US Treasury Note'): 128.6875,
  (Timestamp('2016-09-19 13:30:00'), '30 Day Fed Funds'): 98.879999999999995,
  (Timestamp('2016-09-19 13:30:00'),
   'Bloomberg Commodity Index'): 84.900000000000006,
  (Timestamp('2016-09-19 13:30:00'), 'E-mini S&P 500'): 2126.0,
  (Timestamp('2016-09-19 13:30:00'), 'Gold'): 1341.2,
  (Timestamp('2016-09-19 13:30:00'),
   'Henry Hub Natural Gas'): 4.8129999999999997,
  (Timestamp('2016-09-19 13:30:00'), 'Lean Hogs'): 55.649999999999999,
  (Timestamp('2016-09-19 13:30:00'),
   'Light Sweet Crude Oil'): 49.100000000000001,
  (Timestamp('2016-09-19 13:30:00'), 'Live Cattle'): 97.599999999999994,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Copper Index'): 2.2170000000000001,
  (Timestamp('2016-09-19 13:30:00'),
   'NYMEX Palladium Index'): 681.79999999999995,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Platinum Index'): 1039.0,
  (Timestamp('2016-09-19 13:30:00'),
   'Soybean Meal Futures'): 337.69999999999999,
  (Timestamp('2016-09-19 13:30:00'),
   'Soybean Oil Futures'): 34.299999999999997,
  (Timestamp('2016-09-19 13:30:00'), 'Wheat Futures'): 495.75,
  (Timestamp('2016-09-19 14:00:00'), '10 Year US Treasury Note'): 128.671875,
  (Timestamp('2016-09-19 14:00:00'), '30 Day Fed Funds'): 98.879999999999995,
  (Timestamp('2016-09-19 14:00:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 14:00:00'), 'E-mini S&P 500'): 2132.0,
  (Timestamp('2016-09-19 14:00:00'), 'Gold'): 1339.3,
  (Timestamp('2016-09-19 14:00:00'),
   'Henry Hub Natural Gas'): 4.8380000000000001,
  (Timestamp('2016-09-19 14:00:00'), 'Lean Hogs'): 55.774999999999999,
  (Timestamp('2016-09-19 14:00:00'),
   'Light Sweet Crude Oil'): 49.409999999999997,
  (Timestamp('2016-09-19 14:00:00'), 'Live Cattle'): 97.200000000000003,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Copper Index'): 2.2149999999999999,
  (Timestamp('2016-09-19 14:00:00'),
   'NYMEX Palladium Index'): 684.35000000000002,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Platinum Index'): 1037.0,
  (Timestamp('2016-09-19 14:00:00'),
   'Soybean Meal Futures'): 336.30000000000001,
  (Timestamp('2016-09-19 14:00:00'),
   'Soybean Oil Futures'): 34.469999999999999,
  (Timestamp('2016-09-19 14:00:00'), 'Wheat Futures'): 497.0,
  (Timestamp('2016-09-19 14:30:00'), '10 Year US Treasury Note'): 128.609375,
  (Timestamp('2016-09-19 14:30:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 14:30:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 14:30:00'), 'E-mini S&P 500'): 2131.0,
  (Timestamp('2016-09-19 14:30:00'), 'Gold'): 1339.0999999999999,
  (Timestamp('2016-09-19 14:30:00'),
   'Henry Hub Natural Gas'): 4.8179999999999996,
  (Timestamp('2016-09-19 14:30:00'), 'Lean Hogs'): 55.174999999999997,
  (Timestamp('2016-09-19 14:30:00'),
   'Light Sweet Crude Oil'): 49.719999999999999,
  (Timestamp('2016-09-19 14:30:00'), 'Live Cattle'): 97.200000000000003,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Copper Index'): 2.2149999999999999,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Palladium Index'): 691.25,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Platinum Index'): 1039.0,
  (Timestamp('2016-09-19 14:30:00'),
   'Soybean Meal Futures'): 334.89999999999998,
  (Timestamp('2016-09-19 14:30:00'), 'Soybean Oil Futures'): 34.5,
  (Timestamp('2016-09-19 14:30:00'), 'Wheat Futures'): 494.25,
  (Timestamp('2016-09-19 15:00:00'), '10 Year US Treasury Note'): 128.609375,
  (Timestamp('2016-09-19 15:00:00'), '30 Day Fed Funds'): 98.885000000000005,
  (Timestamp('2016-09-19 15:00:00'),
   'Bloomberg Commodity Index'): 85.099999999999994,
  (Timestamp('2016-09-19 15:00:00'), 'E-mini S&P 500'): 2128.0,
  (Timestamp('2016-09-19 15:00:00'), 'Gold'): 1338.2},
 'volume': {(Timestamp('2016-09-19 13:30:00'),
   '10 Year US Treasury Note'): 30941.0,
  (Timestamp('2016-09-19 13:30:00'), '30 Day Fed Funds'): 251.0,
  (Timestamp('2016-09-19 13:30:00'), 'Bloomberg Commodity Index'): 0.0,
  (Timestamp('2016-09-19 13:30:00'), 'E-mini S&P 500'): 164450.0,
  (Timestamp('2016-09-19 13:30:00'), 'Gold'): 6173.0,
  (Timestamp('2016-09-19 13:30:00'), 'Henry Hub Natural Gas'): 8462.0,
  (Timestamp('2016-09-19 13:30:00'), 'Lean Hogs'): 1489.0,
  (Timestamp('2016-09-19 13:30:00'), 'Light Sweet Crude Oil'): 30803.0,
  (Timestamp('2016-09-19 13:30:00'), 'Live Cattle'): 2970.0,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Copper Index'): 3066.0,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Palladium Index'): 373.0,
  (Timestamp('2016-09-19 13:30:00'), 'NYMEX Platinum Index'): 1014.0,
  (Timestamp('2016-09-19 13:30:00'), 'Soybean Meal Futures'): 4978.0,
  (Timestamp('2016-09-19 13:30:00'), 'Soybean Oil Futures'): 8493.0,
  (Timestamp('2016-09-19 13:30:00'), 'Wheat Futures'): 7462.0,
  (Timestamp('2016-09-19 14:00:00'), '10 Year US Treasury Note'): 40382.0,
  (Timestamp('2016-09-19 14:00:00'), '30 Day Fed Funds'): 526.0,
  (Timestamp('2016-09-19 14:00:00'), 'Bloomberg Commodity Index'): 1250.0,
  (Timestamp('2016-09-19 14:00:00'), 'E-mini S&P 500'): 117841.0,
  (Timestamp('2016-09-19 14:00:00'), 'Gold'): 4891.0,
  (Timestamp('2016-09-19 14:00:00'), 'Henry Hub Natural Gas'): 3945.0,
  (Timestamp('2016-09-19 14:00:00'), 'Lean Hogs'): 729.0,
  (Timestamp('2016-09-19 14:00:00'), 'Light Sweet Crude Oil'): 44921.0,
  (Timestamp('2016-09-19 14:00:00'), 'Live Cattle'): 1380.0,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Copper Index'): 3076.0,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Palladium Index'): 1062.0,
  (Timestamp('2016-09-19 14:00:00'), 'NYMEX Platinum Index'): 624.0,
  (Timestamp('2016-09-19 14:00:00'), 'Soybean Meal Futures'): 3007.0,
  (Timestamp('2016-09-19 14:00:00'), 'Soybean Oil Futures'): 6114.0,
  (Timestamp('2016-09-19 14:00:00'), 'Wheat Futures'): 3592.0,
  (Timestamp('2016-09-19 14:30:00'), '10 Year US Treasury Note'): 32360.0,
  (Timestamp('2016-09-19 14:30:00'), '30 Day Fed Funds'): 0.0,
  (Timestamp('2016-09-19 14:30:00'), 'Bloomberg Commodity Index'): 0.0,
  (Timestamp('2016-09-19 14:30:00'), 'E-mini S&P 500'): 76527.0,
  (Timestamp('2016-09-19 14:30:00'), 'Gold'): 3831.0,
  (Timestamp('2016-09-19 14:30:00'), 'Henry Hub Natural Gas'): 4526.0,
  (Timestamp('2016-09-19 14:30:00'), 'Lean Hogs'): 406.0,
  (Timestamp('2016-09-19 14:30:00'), 'Light Sweet Crude Oil'): 27306.0,
  (Timestamp('2016-09-19 14:30:00'), 'Live Cattle'): 735.0,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Copper Index'): 1394.0,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Palladium Index'): 235.0,
  (Timestamp('2016-09-19 14:30:00'), 'NYMEX Platinum Index'): 419.0,
  (Timestamp('2016-09-19 14:30:00'), 'Soybean Meal Futures'): 3348.0,
  (Timestamp('2016-09-19 14:30:00'), 'Soybean Oil Futures'): 3559.0,
  (Timestamp('2016-09-19 14:30:00'), 'Wheat Futures'): 4125.0,
  (Timestamp('2016-09-19 15:00:00'), '10 Year US Treasury Note'): 23938.0,
  (Timestamp('2016-09-19 15:00:00'), '30 Day Fed Funds'): 0.0,
  (Timestamp('2016-09-19 15:00:00'), 'Bloomberg Commodity Index'): 30.0,
  (Timestamp('2016-09-19 15:00:00'), 'E-mini S&P 500'): 68578.0,
  (Timestamp('2016-09-19 15:00:00'), 'Gold'): 2537.0}}

You should be able to do this by passing tuple of (idx[...], your_value) as the first argument to loc . 您应该能够通过将(idx[...], your_value)元组作为loc的第一个参数来执行此操作。

prices.loc[(idx["2016-09-19 13:30:00":"2016-09-19 14:30:00"], xxx), :]

Example: 例:

prices.loc[(idx["2016-09-19 13:30:00":"2016-09-19 14:30:00"], 'Gold'), :]

                             ID   close    high     low    open  volume
2016-09-19 13:30:00 Gold  33824  1339.4  1341.2  1338.7  1341.2  6173.0
2016-09-19 14:00:00 Gold  33825  1339.1  1340.2  1338.6  1339.3  4891.0
2016-09-19 14:30:00 Gold  33826  1338.2  1339.7  1337.6  1339.1  3831.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM