miindex = pd.MultiIndex.from_product(
[mklbl("A", 4), mklbl("B", 2), mklbl("C", 4), mklbl("D", 2)]
)
micolumns = pd.MultiIndex.from_tuples(
[("a", "foo"), ("a", "bar"), ("b", "foo"), ("b", "bah")], names=["lvl0", "lvl1"]
)
dfmi = (
pd.DataFrame(
np.arange(len(miindex) * len(micolumns)).reshape(
(len(miindex), len(micolumns))
),
index=miindex,
columns=micolumns,
)
.sort_index()
.sort_index(axis=1)
)
dfmi.loc[(slice("A1", "A3"), slice(None), ["C1", "C3"]), :]
idx = pd.IndexSlice
dfmi.loc[idx[:, :, ["C1", "C3"]], idx[:, "foo"]]
mask = dfmi[("a", "foo")] > 200
dfmi.loc[idx[mask, :, ["C1", "C3"]], idx[:, "foo"]]
dfmi.loc(axis=0)[:, :, ["C1", "C3"]]