A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://pandas.pydata.org/docs/dev/user_guide/../reference/api/pandas.MultiIndex.from_frame.html below:

pandas.MultiIndex.from_frame — pandas 3.0.0.dev0+2231.g4f2aa4d2be documentation

pandas.MultiIndex.from_frame#
classmethod MultiIndex.from_frame(df, sortorder=None, names=None)[source]#

Make a MultiIndex from a DataFrame.

Parameters:
dfDataFrame

DataFrame to be converted to MultiIndex.

sortorderint, optional

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

nameslist-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.

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'])

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4