pandas 1.4.2

ParametersReturnsBackRef
rename(self, name, inplace=False)

Able to set new names without level. Defaults to returning new index. Length of names must match number of levels in MultiIndex.

Parameters

name : label or list of labels

Name(s) to set.

inplace : bool, default False

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

Returns

Index or None

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

Alter Index or MultiIndex name.

See Also

Index.set_names

Able to set new names partially and by level.

Examples

This example is valid syntax, but we were not able to check execution
>>> idx = pd.Index(['A', 'C', 'A', 'B'], name='score')
... idx.rename('grade') Index(['A', 'C', 'A', 'B'], dtype='object', name='grade')
This example is valid syntax, but we were not able to check execution
>>> idx = pd.MultiIndex.from_product([['python', 'cobra'],
...  [2018, 2019]],
...  names=['kind', 'year'])
... idx MultiIndex([('python', 2018), ('python', 2019), ( 'cobra', 2018), ( 'cobra', 2019)], names=['kind', 'year'])
This example is valid syntax, but we were not able to check execution
>>> idx.rename(['species', 'year'])
MultiIndex([('python', 2018),
            ('python', 2019),
            ( 'cobra', 2018),
            ( 'cobra', 2019)],
           names=['species', 'year'])
This example is valid syntax, but we were not able to check execution
>>> idx.rename('species')
Traceback (most recent call last):
TypeError: Must pass list-like as `names`.
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.generic.NDFrame.rename_axis pandas.core.generic.NDFrame._set_axis_name pandas.core.indexes.base.Index.set_names

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/indexes/base.py#1844
type: <class 'function'>
Commit: