pandas.DataFrame.rename_axis
-
DataFrame.rename_axis(mapper, axis=0, copy=True, inplace=False)
[source] -
Alter the name of the index or columns.
Parameters: mapper : scalar, list-like, optional
Value to set as the axis name attribute.
axis : {0 or ‘index’, 1 or ‘columns’}, default 0
The index or the name of the axis.
copy : boolean, default True
Also copy underlying data.
inplace : boolean, default False
Modifies the object directly, instead of creating a new Series or DataFrame.
Returns: renamed : Series, DataFrame, or None
The same type as the caller or None if
inplace
is True.See also
-
pandas.Series.rename
- Alter Series index labels or name
-
pandas.DataFrame.rename
- Alter DataFrame index labels or name
-
pandas.Index.rename
- Set new names on index
Notes
Prior to version 0.21.0,
rename_axis
could also be used to change the axis labels by passing a mapping or scalar. This behavior is deprecated and will be removed in a future version. Userename
instead.Examples
Series
>>> s = pd.Series([1, 2, 3]) >>> s.rename_axis("foo") foo 0 1 1 2 2 3 dtype: int64
DataFrame
>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}) >>> df.rename_axis("foo") A B foo 0 1 4 1 2 5 2 3 6
>>> df.rename_axis("bar", axis="columns") bar A B 0 1 4 1 2 5 2 3 6
-
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.23.4/generated/pandas.DataFrame.rename_axis.html