DataFrame.
set_axis
Assign desired index to given axis.
Indexes for column or row labels can be changed by assigning a list-like or Index.
The values for the new index.
The axis to update. The value 0 identifies the rows, and 1 identifies the columns.
Whether to return a new DataFrame instance.
An object of type DataFrame if inplace=False, None otherwise.
See also
DataFrame.rename_axis
Alter the name of the index or columns.
Examples
>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
Change the row labels.
>>> df.set_axis(['a', 'b', 'c'], axis='index') A B a 1 4 b 2 5 c 3 6
Change the column labels.
>>> df.set_axis(['I', 'II'], axis='columns') I II 0 1 4 1 2 5 2 3 6
Now, update the labels inplace.
>>> df.set_axis(['i', 'ii'], axis='columns', inplace=True) >>> df i ii 0 1 4 1 2 5 2 3 6