-
classmethod
MultiIndex.from_product(iterables, sortorder=None,names=<object object>)
Make a MultiIndex from the cartesian product of multiple iterables.
-
Parameters
-
iterable : list/sequence of iterables
Each iterable has unique for each level of the index
-
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.
Changed in version 1.0.0 : If not explicitly provided, names will be inferred from the elments of itrables if an element has a name attribute
-
-
Example
>>> numbers = [1,2,3] >>> colors = ['green','purple'] >>> pd.MultiIndex.from_product([numbers, colors], names=['number','color']) MultiIndex(levels=[[1, 2, 3], ['green', 'purple']], labels=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]], names=['number', 'color'])
-
cartesian product
For two sets A and B, the Cartesian product of A and B is denoted by A × B A\times B A×B and defined as :
A × B = ( a , b ) ∣ a ∈ A a n d b ∈ B A\times B={(a,b)|a\in A \; and\;b\in B} A×B=(a,b)∣a∈Aandb∈B
Cartesian Product is the multiplication of two sets to form the set of all ordered pairs.The first element of the orderd pair belong to first set and second pair belong the second set.
理解pd.MultiIndex.from_product
最新推荐文章于 2022-11-09 07:50:33 发布