pandas.MultiIndex.drop#

MultiIndex.drop(codes, level=None, errors='raise')[source]#

Make a new pandas.MultiIndex with the passed list of codes deleted.

Parameters:
codesarray-like

Must be a list of tuples when level is not specified.

levelint or level name, default None
errorsstr, default ‘raise’
Returns:
MultiIndex

Examples

>>> idx = pd.MultiIndex.from_product([(0, 1, 2), ('green', 'purple')],
...                                  names=["number", "color"])
>>> idx
MultiIndex([(0,  'green'),
            (0, 'purple'),
            (1,  'green'),
            (1, 'purple'),
            (2,  'green'),
            (2, 'purple')],
           names=['number', 'color'])
>>> idx.drop([(1, 'green'), (2, 'purple')])
MultiIndex([(0,  'green'),
            (0, 'purple'),
            (1, 'purple'),
            (2,  'green')],
           names=['number', 'color'])

We can also drop from a specific level.

>>> idx.drop('green', level='color')
MultiIndex([(0, 'purple'),
            (1, 'purple'),
            (2, 'purple')],
           names=['number', 'color'])
>>> idx.drop([1, 2], level=0)
MultiIndex([(0,  'green'),
            (0, 'purple')],
           names=['number', 'color'])