from_fields ](pandas.PeriodIndex.from_fields.html)
    * [ pandas.PeriodIndex.from_ordinals ](pandas.PeriodIndex.from_ordinals.html)
  * [ Date offsets ](../offset_frequency.html)
  * [ Window ](../window.html)
  * [ GroupBy ](../groupby.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * __
  * [ pandas.MultiIndex ](pandas.MultiIndex.html)
  * pandas.Multi... 

#  pandas.MultiIndex.from_frame  #

_ classmethod  _ MultiIndex.  from_frame  (  _ df  _ , _ sortorder  =  None  _
, _ names  =  None  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/indexes/multi.py#L687-L754) #

    

Make a MultiIndex from a DataFrame.

Parameters  :

    

**df** DataFrame

    

DataFrame to be converted to MultiIndex.

**sortorder** int, optional

    

Level of sortedness (must be lexicographically sorted by that level).

**names** list-like, optional

    

If no names are provided, use the column names, or tuple of column names if
the columns is a MultiIndex. If a sequence, overwrite names with the given
sequence.

Returns  :

    

MultiIndex

    

The MultiIndex representation of the given DataFrame.

See also

[ ` MultiIndex.from_arrays  `
](pandas.MultiIndex.from_arrays.html#pandas.MultiIndex.from_arrays
"pandas.MultiIndex.from_arrays")

    

Convert list of arrays to MultiIndex.

[ ` MultiIndex.from_tuples  `
](pandas.MultiIndex.from_tuples.html#pandas.MultiIndex.from_tuples
"pandas.MultiIndex.from_tuples")

    

Convert list of tuples to MultiIndex.

[ ` MultiIndex.from_product  `
](pandas.MultiIndex.from_product.html#pandas.MultiIndex.from_product
"pandas.MultiIndex.from_product")

    

Make a MultiIndex from cartesian product of iterables.

Examples

    
    
    >>> df = pd.DataFrame([['HI', 'Temp'], ['HI', 'Precip'],
    ...                    ['NJ', 'Temp'], ['NJ', 'Precip']],
    ...                   columns=['a', 'b'])
    >>> df
          a       b
    0    HI    Temp
    1    HI  Precip
    2    NJ    Temp
    3    NJ  Precip
    
    
    
    >>> pd.MultiIndex.from_frame(df)
    MultiIndex([('HI',   'Temp'),
                ('HI', 'Precip'),
                ('NJ',   'Temp'),
                ('NJ', 'Precip')],
               names=['a', 'b'])
    

Using explicit names, instead of the column names

    
    
    >>> pd.MultiIndex.from_frame(df, names=['state', 'observation'])
    MultiIndex([('HI',   'Temp'),
                ('HI', 'Precip'),
                ('NJ',   'Temp'),
                ('NJ', 'Precip')],
               names=['state', 'observation'])
    

[ __ previous  pandas.MultiIndex.from_product
](pandas.MultiIndex.from_product.html "previous page") [ next
pandas.MultiIndex.set_levels  __ ](pandas.MultiIndex.set_levels.html "next
page")

__ On this page

  * ` MultiIndex.from_frame()  `

[ __ Show Source
](../../_sources/reference/api/pandas.MultiIndex.from_frame.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.