Using pandas IndexSlice, is it possible to use a list of integers? I get KeyError: 'the label [xxxx] is not in the [columns]' when I use a list of integers (even when the values in the multiIndex level are formatted as strings):
vals = np.random.randn(4)
df = pd.DataFrame({'l1': ['A', 'B', 'C', 'B'], 'l2': ['9876', '6789', '5432',
'1234'], 'l3': ['Y', 'X', 'Y', 'Y'], 'value': vals})
df.set_index(['l1', 'l2', 'l3'], inplace=True)
idx = pd.IndexSlice
# None of the following works
df.loc[idx[:, 6789, :]]
df.loc[idx[:, [6789, 1234], :]]
df.reset_index(inplace=True)
df.l2 = df.l2.astype('str')
df.set_index(['l1', 'l2', 'l3'], inplace=True)
df.loc[idx[:, '6789', :]]