Series.
rename_axis
Set the name of the axis for the index or columns.
A scalar, list-like, dict-like or functions transformations to apply to the index values.
Modifies the object directly, instead of creating a new Series.
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 = ps.Series(["dog", "cat", "monkey"], name="animal") >>> s 0 dog 1 cat 2 monkey Name: animal, dtype: object >>> s.rename_axis("index").sort_index() index 0 dog 1 cat 2 monkey Name: animal, dtype: object
MultiIndex
>>> index = pd.MultiIndex.from_product([['mammal'], ... ['dog', 'cat', 'monkey']], ... names=['type', 'name']) >>> s = ps.Series([4, 4, 2], index=index, name='num_legs') >>> s type name mammal dog 4 cat 4 monkey 2 Name: num_legs, dtype: int64 >>> s.rename_axis(index={'type': 'class'}).sort_index() class name mammal cat 4 dog 4 monkey 2 Name: num_legs, dtype: int64 >>> s.rename_axis(index=str.upper).sort_index() TYPE NAME mammal cat 4 dog 4 monkey 2 Name: num_legs, dtype: int64