Allowing empty slice in multi-indices by SylvainCorlay · Pull Request #8781 · pandas-dev/pandas (original) (raw)

This solves #8737 in the case where there is at least one boolean indexer. The patch of #8739 does not allow the following:

import pandas as pd import numpy as np multi_index = pd.MultiIndex.from_product((['foo', 'bar', 'baz'], ['alpha', 'beta'])) df = pd.DataFrame(np.random.randn(5, 6), index=range(5), columns=multi_index) df = df.sortlevel(0, axis=1) df.loc[:, (['foo'], [])]