def to_frame(self, index=True, name=None):
from pandas import DataFrame<EOL>if name is not None:<EOL><INDENT>if not is_list_like(name):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if len(name) != len(self.levels):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>idx_names = name<EOL><DEDENT>else:<EOL><INDENT>idx_names = self.names<EOL><DEDENT>result = DataFrame(<EOL>OrderedDict([<EOL>((level if lvlname is None else lvlname),<EOL>self._get_level_values(level))<EOL>for lvlname, level in zip(idx_names, range(len(self.levels)))<EOL>]),<EOL>copy=False<EOL>)<EOL>if index:<EOL><INDENT>result.index = self<EOL><DEDENT>return result<EOL>
Create a DataFrame with the levels of the MultiIndex as columns.

Column ordering is determined by the DataFrame constructor with data as
a dict.

.. versionadded:: 0.24.0

Parameters
----------
index : boolean, default True
    Set the index of the returned DataFrame as the original MultiIndex.

name : list / sequence of strings, optional
    The passed names should substitute index level names.

Returns
-------
DataFrame : a DataFrame containing the original MultiIndex data.

See Also
--------
DataFrame