pandas.DataFrame.rename_axis

pandas 3.1.1 · DataFrame · method

Change the name of an axis while preserving its labels.

Call syntax

DataFrame.rename_axis(mapper=…, *, index=…, columns=…, axis=0, copy=…, inplace=…)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
mapper Optional
Positional or keyword
scalar, list-like

Provide a dictionary or callable that maps input values or labels.

index Optional
Keyword only
scalar, list-like, dict-like or function

Supply row labels or control how existing row labels are used.

columns Optional
Keyword only
scalar, list-like, dict-like or function

Supply column labels or control how columns are handled.

axis Optional
Keyword only
Default 0
{0 or 'index', 1 or 'columns'}

Choose which axis the operation acts on. The accepted axis labels depend on the receiver.

copy Optional
Keyword only
bool

Control whether data is copied where the API supports that choice.

inplace Optional
Keyword only
bool

Choose whether to change the existing object. Where supported, an in-place call typically returns None.

Returns

DataFrame, or None