Table Of Contents


Enter search terms or a module, class or function name.


class pandas.MultiIndex[source]

A multi-level, or hierarchical, index object for pandas objects


levels : sequence of arrays

The unique labels for each level

labels : sequence of arrays

Integers for each level designating which label at each location

sortorder : optional int

Level of sortedness (must be lexicographically sorted by that level)

names : optional sequence of objects

Names for each of the index levels. (name is accepted for compat)

copy : boolean, default False

Copy the meta-data

verify_integrity : boolean, default True

Check that the levels/labels are consistent and valid

See also

Convert list of arrays to MultiIndex
Create a MultiIndex from the cartesian product of iterables
Convert list of tuples to a MultiIndex
The base pandas Index type


See the user guide for more.


A new MultiIndex is typically constructed using one of the helper methods MultiIndex.from_arrays(), MultiIndex.from_product() and MultiIndex.from_tuples(). For example (using .from_arrays):

>>> arrays = [[1, 1, 2, 2], ['red', 'blue', 'red', 'blue']]
>>> pd.MultiIndex.from_arrays(arrays, names=('number', 'color'))
MultiIndex(levels=[[1, 2], ['blue', 'red']],
       labels=[[0, 0, 1, 1], [1, 0, 1, 0]],
       names=['number', 'color'])

See further examples for how to construct a MultiIndex in the doc strings of the mentioned helper methods.


T return the transpose, which is by definition self
base return the base object if the memory of the underlying data is
data return the data pointer of the underlying data
itemsize return the size of the dtype of the item of the underlying data
names Names of levels in MultiIndex
ndim return the number of dimensions of the underlying data,
shape return a tuple of the shape of the underlying data
size return the number of elements in the underlying data
strides return the strides of the underlying data


append(other) Append a collection of Index options together
argmax([axis]) return a ndarray of the maximum argument indexer
argmin([axis]) return a ndarray of the minimum argument indexer
argsort(*args, **kwargs)
asof(label) For a sorted index, return the most recent label up to and including the passed label.
asof_locs(where, mask) where : array of timestamps
astype(dtype[, copy]) Create an Index with values cast to dtypes.
contains(key) return a boolean if this key is IN the index
copy([names, dtype, levels, labels, deep, ...]) Make a copy of this object.
delete(loc) Make new index with passed location deleted
difference(other) Compute sorted set difference of two MultiIndex objects
drop(labels[, level, errors]) Make new MultiIndex with passed list of labels deleted
drop_duplicates([keep]) Return Index with duplicate values removed
droplevel([level]) Return Index with requested level removed.
dropna([how]) Return Index without NA/NaN values
duplicated([keep]) Return boolean np.ndarray denoting duplicate values
equal_levels(other) Return True if the levels of both MultiIndex objects are the same
equals(other) Determines if two MultiIndex objects have the same labeling information
factorize([sort, na_sentinel]) Encode the object as an enumerated type or categorical variable
fillna([value, downcast]) fillna is not implemented for MultiIndex
format([space, sparsify, adjoin, names, ...])
from_arrays(arrays[, sortorder, names]) Convert arrays to MultiIndex
from_product(iterables[, sortorder, names]) Make a MultiIndex from the cartesian product of multiple iterables
from_tuples(tuples[, sortorder, names]) Convert list of tuples to MultiIndex
get_indexer(target[, method, limit, tolerance]) Compute indexer and mask for new index given the current index.
get_indexer_for(target, **kwargs) guaranteed return of an indexer even when non-unique
get_indexer_non_unique(target) Compute indexer and mask for new index given the current index.
get_level_values(level) Return vector of label values for requested level, equal to the length of the index.
get_loc(key[, method]) Get location for a label or a tuple of labels as an integer, slice or boolean mask.
get_loc_level(key[, level, drop_level]) Get both the location for the requested label(s) and the resulting sliced index.
get_locs(seq) Get location for a given label/slice/list/mask or a sequence of such as an array of integers.
get_major_bounds([start, end, step, kind]) For an ordered MultiIndex, compute the slice locations for input labels.
get_slice_bound(label, side, kind)
get_value(series, key)
get_values() return the underlying data as an ndarray
groupby(values) Group the index labels by a given array of values.
identical(other) Similar to equals, but check that other comparable attributes are
insert(loc, item) Make new MultiIndex inserting new item at location
intersection(other) Form the intersection of two MultiIndex objects, sorting if possible
is_(other) More flexible, faster check like is but that works through views
is_lexsorted() Return True if the labels are lexicographically sorted
isin(values[, level]) Compute boolean array of whether each index value is found in the passed set of values.
isna() Detect missing values
isnull() Detect missing values
item() return the first element of the underlying data as a python
join(other[, how, level, return_indexers, sort]) this is an internal non-public method
map(mapper) Apply mapper function to an index.
max() The maximum value of the object
memory_usage([deep]) Memory usage of my values
min() The minimum value of the object
notna() Inverse of isna
notnull() Inverse of isna
nunique([dropna]) Return number of unique elements in the object.
putmask(mask, value) return a new Index of the values set with the mask
ravel([order]) return an ndarray of the flattened values of the underlying data
reindex(target[, method, level, limit, ...]) Create index with target’s values (move/add/delete values as necessary)
remove_unused_levels() create a new MultiIndex from the current that removing
rename(names[, level, inplace]) Set new names on index.
reorder_levels(order) Rearrange levels using input order.
repeat(repeats, *args, **kwargs)
reshape(*args, **kwargs) NOT IMPLEMENTED: do not call this method, as reshaping is not supported for Index objects and will raise an error.
searchsorted(value[, side, sorter]) Find indices where elements should be inserted to maintain order.
set_labels(labels[, level, inplace, ...]) Set new labels on MultiIndex.
set_levels(levels[, level, inplace, ...]) Set new levels on MultiIndex.
set_names(names[, level, inplace]) Set new names on index.
set_value(arr, key, value) Fast lookup of value from 1-dimensional ndarray.
shift([periods, freq]) Shift Index containing datetime objects by input number of periods and
slice_indexer([start, end, step, kind]) For an ordered Index, compute the slice indexer for input labels and
slice_locs([start, end, step, kind]) For an ordered MultiIndex, compute the slice locations for input labels.
sort(*args, **kwargs)
sort_values([return_indexer, ascending]) Return sorted copy of Index
sortlevel([level, ascending, sort_remaining]) Sort MultiIndex at the requested level.
str alias of StringMethods
swaplevel([i, j]) Swap level i with level j.
symmetric_difference(other[, result_name]) Compute the symmetric difference of two Index objects.
take(indices[, axis, allow_fill, fill_value]) return a new MultiIndex of the values selected by the indices
to_datetime([dayfirst]) DEPRECATED: use pandas.to_datetime() instead.
to_frame([index]) Create a DataFrame with the levels of the MultiIndex as columns.
to_hierarchical(n_repeat[, n_shuffle]) Return a MultiIndex reshaped to conform to the shapes given by n_repeat and n_shuffle.
to_native_types([slicer]) Format specified values of self and return them.
to_series(**kwargs) Create a Series with both index and values equal to the index keys
tolist() Return a list of the values.
transpose(*args, **kwargs) return the transpose, which is by definition self
truncate([before, after]) Slice index between two labels / tuples, return new MultiIndex
union(other) Form the union of two MultiIndex objects, sorting if possible
unique() Return unique values in the object.
value_counts([normalize, sort, ascending, ...]) Returns object containing counts of unique values.
view([cls]) this is defined as a copy with the same identity
where(cond[, other])
Scroll To Top