pandas.Series.rename_axis — pandas 3.0.0.dev0+2104.ge637b4290d documentation (original) (raw)
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-Writewill be enabled by default, which means that all methods with acopy 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
.
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