pandas.DataFrame.set_axis

pandas 3.1.1 · DataFrame · method

Replace all labels on an axis with a new collection of equal length.

Call syntax

DataFrame.set_axis(labels, *, axis=0, copy=…)

Run the example

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

Parameters

ParameterRequirementAccepted values and behavior
labels Required
Positional or keyword
list-like, Index

Provide the labels used for selecting rows, renaming entries, or naming bins.

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.

Returns

DataFrame