pandas.MultiIndex

class pandas.MultiIndex[source]

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

Parameters:

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

Attributes

T return the transpose, which is by definition self
asi8
base return the base object if the memory of the underlying data is
data return the data pointer of the underlying data
dtype
dtype_str
empty
flags
has_duplicates
hasnans
inferred_type
is_all_dates
is_monotonic
is_monotonic_decreasing return if the index is monotonic decreasing (only equal or
is_monotonic_increasing
is_unique
itemsize return the size of the dtype of the item of the underlying data
labels
levels
levshape
lexsort_depth
name
names Names of levels in MultiIndex
nbytes
ndim return the number of dimensions of the underlying data,
nlevels
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
values

Methods

all([other])
any([other])
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]) Fill NA/NaN values with the specified value
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_duplicates()
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,
get_loc(key[, method]) Get integer location, slice or boolean mask for requested label or tuple.
get_loc_level(key[, level, drop_level]) Get integer location slice for requested label or tuple
get_locs(tup) Given a tuple of slices/lists/labels/boolean indexer to a level-wise
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.
holds_integer()
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_boolean()
is_categorical()
is_floating()
is_integer()
is_interval()
is_lexsorted() Return True if the labels are lexicographically sorted
is_lexsorted_for_tuple(tup) Return True if we are correctly lexsorted given the passed tuple
is_mixed()
is_numeric()
is_object()
is_type_compatible(kind)
isin(values[, level]) Compute boolean array of whether each index value is found in the passed set of 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
notnull() Reverse of isnull
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
summary([name])
swaplevel([i, j]) Swap level i with level j.
sym_diff(*args, **kwargs)
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 columns the levels of the MultiIndex
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 Index 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