MultiIndex.
to_frame
Create a DataFrame with the levels of the MultiIndex as columns. Column ordering is determined by the DataFrame constructor with data as a dict.
Set the index of the returned DataFrame as the original MultiIndex.
The passed names should substitute index level names.
See also
DataFrame
Examples
>>> tuples = [(1, 'red'), (1, 'blue'), ... (2, 'red'), (2, 'blue')] >>> idx = ps.MultiIndex.from_tuples(tuples, names=('number', 'color')) >>> idx MultiIndex([(1, 'red'), (1, 'blue'), (2, 'red'), (2, 'blue')], names=['number', 'color']) >>> idx.to_frame() number color number color 1 red 1 red blue 1 blue 2 red 2 red blue 2 blue
By default, the original Index is reused. To enforce a new Index:
>>> idx.to_frame(index=False) number color 0 1 red 1 1 blue 2 2 red 3 2 blue
To override the name of the resulting column, specify name:
>>> idx.to_frame(name=['n', 'c']) n c number color 1 red 1 red blue 1 blue 2 red 2 red blue 2 blue