pandas.MultiIndex.to_frame

pandas 3.1.1 · Index objects · method

Create a DataFrame with one column per MultiIndex level.

Call syntax

MultiIndex.to_frame(index=True, name=…, allow_duplicates=False)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
index Optional
Positional or keyword
Default True
bool

Supply row labels or control how existing row labels are used.

name Optional
Positional or keyword
list / sequence of str

Set a name or identify the named object used by the operation.

allow_duplicates Optional
Positional or keyword
Default False
bool, optional default False

Choose whether duplicate labels are permitted by the operation.

Returns

DataFrame