- API reference
- pandas.MultiIndex
- pandas.Multi...
pandas.MultiIndex.to_frame#
- MultiIndex.to_frame(index=True,name=<no_default>,allow_duplicates=False)[source]#
Create a DataFrame with the levels of the MultiIndex as columns.
Column ordering is determined by the DataFrame constructor with data asa dict.
- Parameters:
- indexbool, default True
Set the index of the returned DataFrame as the original MultiIndex.
- namelist / sequence of str, optional
The passed names should substitute index level names.
- allow_duplicatesbool, optional default False
Allow duplicate column labels to be created.
Added in version 1.5.0.
- Returns:
- DataFrame
See also
DataFrame
Two-dimensional, size-mutable, potentially heterogeneous tabular data.
Examples
>>>mi=pd.MultiIndex.from_arrays([['a','b'],['c','d']])>>>miMultiIndex([('a', 'c'), ('b', 'd')], )
>>>df=mi.to_frame()>>>df 0 1a c a cb d b d
>>>df=mi.to_frame(index=False)>>>df 0 10 a c1 b d
>>>df=mi.to_frame(name=['x','y'])>>>df x ya c a cb d b d
On this page