Why do I see all original index elements in a sliced dataframe? [duplicate]
问题 This question already has answers here : How do you update the levels of a pandas MultiIndex after slicing its DataFrame? (3 answers) Closed 2 years ago . I have a multiindex dataframe like this: import pandas as pd import numpy as np df = pd.DataFrame({'ind1': list('aaaaaaaaabbbbbbbbb'), 'ind2': list('cccdddeeecccdddeee'), 'ind3': list(range(3))*6, 'val1': list(range(100, 118)), 'val2': list(range(70, 88))}) df_mult = df.set_index(['ind1', 'ind2', 'ind3']) val1 val2 ind1 ind2 ind3 a c 0 100