pandas.MultiIndex.from_tuples¶
-
classmethod
MultiIndex.
from_tuples
(tuples, sortorder=None, names=None)[source]¶ Convert list of tuples to MultiIndex.
Parameters: - tuples : list / sequence of tuple-likes
Each tuple is the index of one row/column.
- sortorder : int or None
Level of sortedness (must be lexicographically sorted by that level).
- names : list / sequence of str, optional
Names for the levels in the index.
Returns: - index : MultiIndex
See also
MultiIndex.from_arrays
- Convert list of arrays to MultiIndex.
MultiIndex.from_product
- Make a MultiIndex from cartesian product of iterables.
MultiIndex.from_frame
- Make a MultiIndex from a DataFrame.
Examples
>>> tuples = [(1, u'red'), (1, u'blue'), ... (2, u'red'), (2, u'blue')] >>> pd.MultiIndex.from_tuples(tuples, names=('number', 'color')) MultiIndex(levels=[[1, 2], ['blue', 'red']], codes=[[0, 0, 1, 1], [1, 0, 1, 0]], names=['number', 'color'])