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.
Syntax:
Series.rename_axis(self, mapper=None, index=None, columns=None, axis=None, copy=True, inplace=False)
Parameters:
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 |
Required |
copy | Also copy underlying data. | bool Default Value: True |
Required |
inplace | Modifies the object directly, instead of creating a new Series or DataFrame. | bool Default Value: False |
Required |
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 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.
Example:
Download the Pandas Series Notebooks from here.
Previous: Alter Series index in Pandas
Next: Generate a new Pandas series with the index reset
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework