In [2]:
df
Out[2]:
a b c
0 4.0 7 10.0
1 5.0 8 11.0
2 NaN 9 NaN

DataFrame

Rename index axis.

In [3]:
df.rename_axis("idx")
Out[3]:
a b c
idx
0 4.0 7 10.0
1 5.0 8 11.0
2 NaN 9 NaN

Rename columns axis.

In [4]:
df.rename_axis("cols", axis="columns")
Out[4]:
cols a b c
0 4.0 7 10.0
1 5.0 8 11.0
2 NaN 9 NaN

Rename index and columns axes.

In [5]:
df.rename_axis(index="idx", columns="cols")
Out[5]:
cols a b c
idx
0 4.0 7 10.0
1 5.0 8 11.0
2 NaN 9 NaN

MultiIndex

Change the name of a MultiIndex.

In [7]:
df
Out[7]:
a b c
0 a 4.0 7 10.0
1 b 5.0 8 11.0
2 c NaN 9 NaN
In [8]:
df.rename_axis(['idx1','idx2'])
Out[8]:
a b c
idx1 idx2
0 a 4.0 7 10.0
1 b 5.0 8 11.0
2 c NaN 9 NaN