pandas.Series.rename_axis#

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.

Parameters:
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.

Note

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.

Returns:
Series, or None

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

See also

Series.rename

Alter Series index labels or name.

DataFrame.rename

Alter DataFrame index labels or name.

Index.rename

Set new names on index.

Examples

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