pyspark.pandas.Series.rename_axis#
- Series.rename_axis(mapper=None, index=None, inplace=False)[source]#
Set the name of the axis for the index or columns.
- Parameters
- mapper, indexscalar, list-like, dict-like or function, optional
A scalar, list-like, dict-like or functions transformations to apply to the index values.
- inplacebool, default False
Modifies the object directly, instead of creating a new Series.
- Returns
- Series, or None if inplace is 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 = 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