Question: Consider this Pandas data frame with a MultiIndex: df = pd.DataFrame({'x': [1, 2, 3, 4]}) arrays = [[1, 1, 2, 2], [False, True, False, True]] df.index = pd.MultiIndex.from_arrays(arrays, names=('grp', 'is_even')) df x grp is_even 1 False 1 True 2 2 False 3 True 4  I can select a specific entry - say, grp == 1 & is_even == True: df.loc[(1, True)] x 2 Name: (1, True), dtype: int64  And with slice or pd.IndexSlice notation, I can select a specific value for the first index level (grp == 1), along with all values of the second level: # with slice() df.loc[slice(1), slice(None)] x grp is_even 1 False 1 True 2 # with pd.IndexSlice idx = pd.IndexSlice df.loc[idx[1, :]] # note - correct rows selected but grp index level not shown x is_even False 1 True 2  But when I try to select all values of the first index level, and a specific value for the second index level (e.g. is_even == True), this syntax pattern fails (KeyError on the second index level's value). df.loc[idx[:, True]] # also throws KeyError with df.loc[(slice(None), slice(True))] --------------------------------------------------------------------------- KeyError Traceback (most recent call last) ~/anaconda3/envs/betterup-example-analysis/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance) 2645 try: -> 2646 return self._engine.get_loc(key) 2647 except KeyError: # ...  The error trace is long (and reproducible with this code if it's helpful to see it all), but one segment has a couple of comments that hint at where the problem is (in bold):  ~/anaconda3/envs/betterup-example-analysis/lib/python3.6/site-packages/pandas/core/indexing.py in _getitem_lowerdim(self, tup) 1371 # we may have a nested tuples indexer here 1372 if self._is_nested_tuple_indexer(tup): -> 1373 return self._getitem_nested_tuple(tup) 1374 1375 # we maybe be using a tuple to represent multiple dimensions here  After some experimentation, I found that adding a column placeholder resolves the error. (Doing this also restores the missing first index level in the IndexSlice example above.) df.loc[idx[:, True], :] x grp is_even 1 True 2 2 True 4  I also found I can get there with query: df.query('is_even == True')  So I'm happy I have a fix, but my Pandas-fu isn't strong enough to understand why the error happens without including the column placeholder. If someone can help me grok what's happening here, I'd really appreciate it! Pandas version: 1.0.5 Python version: 3.6.15

Answer: idx[:, True] is actually just a wrapper to create: (slice(None, None, None), True)  So when you pass it to slice, this uses the first part for the index and the second for the columns. By doing df.loc[idx[:, True], :] you make it explicit that the columns slicer is : A further demonstration is trying to run df.loc[idx[:, 'x']], which will correctly slice the column x.  When running df.loc[slice(1, True), 'x'],you are not using 1 for the first level and True for the second but rather doing: df.loc[1:True, 'x']  If you want to get the item at index (1, True) and column x, use: df.loc[(1, True), 'x'] # 2  If you want all values of the first level, just the True in the second level and column x: df.loc[(slice(None), True), 'x'] grp is_even 1 True 2 2 True 4 Name: x, dtype: int64