pandas.MultiIndex.from_product

classmethod MultiIndex.from_product(iterables, sortorder=None, names=None)[source]

Make a MultiIndex from the cartesian product of multiple iterables

Parameters:

iterables : list / sequence of iterables

Each iterable has unique labels for each level of the index.

sortorder : int or None

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

names : list / sequence of strings or None

Names for the levels in the index.

Returns:

index : MultiIndex

See also

MultiIndex.from_arrays
Convert list of arrays to MultiIndex
MultiIndex.from_tuples
Convert list of tuples to MultiIndex

Examples

>>> numbers = [0, 1, 2]
>>> colors = [u'green', u'purple']
>>> MultiIndex.from_product([numbers, colors],
                             names=['number', 'color'])
MultiIndex(levels=[[0, 1, 2], [u'green', u'purple']],
           labels=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],
           names=[u'number', u'color'])
Scroll To Top