pandas.MultiIndex.truncate#
- MultiIndex.truncate(before=None, after=None)[source]#
Slice index between two labels / tuples, return new MultiIndex.
- Parameters:
- beforelabel or tuple, can be partial. Default None
None defaults to start.
- afterlabel or tuple, can be partial. Default None
None defaults to end.
- Returns:
- MultiIndex
The truncated MultiIndex.
See also
DataFrame.truncate
Truncate a DataFrame before and after some index values.
Series.truncate
Truncate a Series before and after some index values.
Examples
>>> mi = pd.MultiIndex.from_arrays([["a", "b", "c"], ["x", "y", "z"]]) >>> mi MultiIndex([('a', 'x'), ('b', 'y'), ('c', 'z')], ) >>> mi.truncate(before="a", after="b") MultiIndex([('a', 'x'), ('b', 'y')], )