Index.set_names(names, level=None, inplace=False)[source]#

Set Index or MultiIndex name. Able to set new names partially and by level.

nameslabel or list of label

Name(s) to set.

levelint, label or list of int or label, optional

If the index is a MultiIndex, level(s) to set (None for all levels). Otherwise level must be None.

inplacebool, default False

Modifies the object directly, instead of creating a new Index or MultiIndex.


The same type as the caller or None if inplace is True.

See also


Able to set new names without level.


>>> import cudf
>>> idx = cudf.Index([1, 2, 3, 4])
>>> idx
Index([1, 2, 3, 4], dtype='int64')
>>> idx.set_names('quarter')
Index([1, 2, 3, 4], dtype='int64', name='quarter')
>>> idx = cudf.MultiIndex.from_product([['python', 'cobra'],
... [2018, 2019]])
>>> idx
MultiIndex([('python', 2018),
            ('python', 2019),
            ( 'cobra', 2018),
            ( 'cobra', 2019)],
>>> idx.names
FrozenList([None, None])
>>> idx.set_names(['kind', 'year'], inplace=True)
>>> idx.names
FrozenList(['kind', 'year'])
>>> idx.set_names('species', level=0, inplace=True)
>>> idx.names
FrozenList(['species', 'year'])