class pandas.MultiIndex [source]
A multi-level, or hierarchical, index object for pandas objects.
| Parameters: |
|
|---|
See also
MultiIndex.from_arrays
MultiIndex.from_product
MultiIndex.from_tuples
MultiIndex.from_frame
Index
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([(1, 'red'),
(1, 'blue'),
(2, 'red'),
(2, 'blue')],
names=['number', 'color'])
See further examples for how to construct a MultiIndex in the doc strings of the mentioned helper methods.
names | Names of levels in MultiIndex |
nlevels | Integer number of levels in this MultiIndex. |
levshape | A tuple with the length of each level. |
| levels | |
| codes |
from_arrays(arrays[, sortorder, names]) | Convert arrays to MultiIndex. |
from_tuples(tuples[, sortorder, names]) | Convert list of tuples to MultiIndex. |
from_product(iterables[, sortorder, names]) | Make a MultiIndex from the cartesian product of multiple iterables. |
from_frame(df[, sortorder, names]) | Make a MultiIndex from a DataFrame. |
set_levels(self, levels[, level, inplace, …]) | Set new levels on MultiIndex. |
set_codes(self, codes[, level, inplace, …]) | Set new codes on MultiIndex. |
to_frame(self[, index, name]) | Create a DataFrame with the levels of the MultiIndex as columns. |
to_flat_index(self) | Convert a MultiIndex to an Index of Tuples containing the level values. |
is_lexsorted(self) | Return True if the codes are lexicographically sorted |
sortlevel(self[, level, ascending, …]) | Sort MultiIndex at the requested level. |
droplevel(self[, level]) | Return index with requested level(s) removed. |
swaplevel(self[, i, j]) | Swap level i with level j. |
reorder_levels(self, order) | Rearrange levels using input order. |
remove_unused_levels(self) | Create a new MultiIndex from the current that removes unused levels, meaning that they are not expressed in the labels. |
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.MultiIndex.html