rename_axis(self, mapper=None, index=None, columns=None, axis=None, copy=True, inplace=False)
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 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.
Value to set the axis name attribute.
A scalar, list-like, dict-like or functions transformations to apply to that axis' values. Note that the columns
parameter is not allowed if the object is a Series. This parameter only apply for DataFrame type objects.
Use either mapper
and axis
to specify the axis to target with mapper
, or index
and/or columns
.
The axis to rename.
Also copy underlying data.
Modifies the object directly, instead of creating a new Series or DataFrame.
The same type as the caller or None if inplace=True
.
Set the name of the axis for the index or columns.
DataFrame.rename
Alter DataFrame index labels or name.
Index.rename
Set new names on index.
Series.rename
Alter Series index labels or name.
Series
This example is valid syntax, but we were not able to check execution>>> s = pd.Series(["dog", "cat", "monkey"])This example is valid syntax, but we were not able to check execution
... s 0 dog 1 cat 2 monkey dtype: object
>>> s.rename_axis("animal") animal 0 dog 1 cat 2 monkey dtype: object
DataFrame
This example is valid syntax, but we were not able to check execution>>> df = pd.DataFrame({"num_legs": [4, 4, 2],This example is valid syntax, but we were not able to check execution
... "num_arms": [0, 0, 2]},
... ["dog", "cat", "monkey"])
... df num_legs num_arms dog 4 0 cat 4 0 monkey 2 2
>>> df = df.rename_axis("animal")This example is valid syntax, but we were not able to check execution
... df num_legs num_arms animal dog 4 0 cat 4 0 monkey 2 2
>>> df = df.rename_axis("limbs", axis="columns")
... df limbs num_legs num_arms animal dog 4 0 cat 4 0 monkey 2 2
MultiIndex
This example is valid syntax, but we were not able to check execution>>> df.index = pd.MultiIndex.from_product([['mammal'],This example is valid syntax, but we were not able to check execution
... ['dog', 'cat', 'monkey']],
... names=['type', 'name'])
... df limbs num_legs num_arms type name mammal dog 4 0 cat 4 0 monkey 2 2
>>> df.rename_axis(index={'type': 'class'}) limbs num_legs num_arms class name mammal dog 4 0 cat 4 0 monkey 2 2This example is valid syntax, but we were not able to check execution
>>> df.rename_axis(columns=str.upper) LIMBS num_legs num_arms type name mammal dog 4 0 cat 4 0 monkey 2 2See :
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.generic.NDFrame._rename
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them