hipdf.MultiIndex.from_frame

hipdf.MultiIndex.from_frame#

21 min read time

Applies to Linux

classmethod MultiIndex.from_frame(df, names=None)#

Make a MultiIndex from a DataFrame.

Parameters#

dfDataFrame

DataFrame to be converted to MultiIndex.

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.

See Also#

MultiIndex.from_tuples : Convert list of tuples to MultiIndex. MultiIndex.from_product : Make a MultiIndex from cartesian product

of iterables.

Examples#

>>> import cudf
>>> df = cudf.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
>>> cudf.MultiIndex.from_frame(df)
MultiIndex([('HI',   'Temp'),
            ('HI', 'Precip'),
            ('NJ',   'Temp'),
            ('NJ', 'Precip')],
           names=['a', 'b'])

Using explicit names, instead of the column names

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