Series.rename_axis(mapper=<no_default>, *, index=<no_default>, axis=0, copy=<no_default>, inplace=False)[source]#

Set the name of the axis for the index.

mapperscalar, list-like, optional

Value to set the axis name attribute.

Use either mapper and axis to specify the axis to target with mapper, or index.

indexscalar, list-like, dict-like or function, optional

A scalar, list-like, dict-like or functions transformations to apply to that axis’ values.

axis{0 or ‘index’}, default 0

The axis to rename. For Series this parameter is unused and defaults to 0.

copybool, default False

Also copy underlying data.


The copy keyword will change behavior in pandas 3.0. Copy-on-Write will be enabled by default, which means that all methods with a copy keyword will use a lazy copy mechanism to defer the copy and ignore the copy keyword. The copy keyword will be removed in a future version of pandas.

You can already get the future behavior and improvements through enabling copy on write pd.options.mode.copy_on_write = True

inplacebool, default False

Modifies the object directly, instead of creating a new Series or DataFrame.

Series, or None

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

See also


Alter Series index labels or name.


Alter DataFrame index labels or name.


Set new names on index.


>>> s = pd.Series(["dog", "cat", "monkey"])
>>> s
0       dog
1       cat
2    monkey
dtype: object
>>> s.rename_axis("animal")
0    dog
1    cat
2    monkey
dtype: object