Pandas Series: rename_axis() function

Set the name of the axis in Pandas

The rename_axis() function is used to set the name of the axis for the index or columns.


Series.rename_axis(self, mapper=None, index=None, columns=None, axis=None, copy=True, inplace=False)
Pandas Series rename_axis image


Name Description Type/Default Value Required / Optional
mapper Value to set the axis name attribute. scalar, list-like optional
index, columns A scalar, list-like, dict-like or functions transformations to apply to that axis’ values.
Use either mapper and axis to specify the axis to target with mapper, or index and/or columns.
scalar, list-like, dict-like or function, optional
axis The axis to rename. {0 or ‘index’, 1 or ‘columns’}
Default Value: 0
copy Also copy underlying data. bool
Default Value: True
inplace Modifies the object directly, instead of creating a new Series or DataFrame. bool
Default Value: False

Returns: Series,DataFrame, or None - The same type as the caller or None if inplace is True.

Notes: DataFrame.rename_axis supports two calling conventions

  • (index=index_mapper, columns=columns_mapper, ...)
  • mapper, axis={'index', 'columns'}, ...)
The first calling convention will only modify the names of the index and/or the names of the Index object that is the columns. In this case, the parameter copy is ignored.
The second calling convention will modify the names of the the corresponding index if mapper is a list or a scalar. However, if mapper is dict-like or a function, it will use the deprecated behavior of modifying the axis labels.
We highly recommend using keyword arguments to clarify your intent.


Download the above Notebook from here.

Previous: Alter Series index in Pandas
Next: Generate a new Pandas series with the index reset