Examples
DataFrame.rename supports two calling conventions:

In [1]:
import numpy as np
import pandas as pd
In [2]:
df = pd.DataFrame({"P": [2, 3, 4], "Q": [5, 6, 7]})
df.rename(columns={"P": "p", "Q": "r"})
Out[2]:
p r
0 2 5
1 3 6
2 4 7

Rename index using a mapping:

In [3]:
df.rename(index={0: "x", 1: "y", 2: "z"})
Out[3]:
P Q
x 2 5
y 3 6
z 4 7

Cast index labels to a different type:

In [4]:
df.index
Out[4]:
RangeIndex(start=0, stop=3, step=1)
In [5]:
df.rename(index=str).index
Out[5]:
Index(['0', '1', '2'], dtype='object')

Using axis-style parameters:

In [6]:
df.rename(str.lower, axis='columns')
Out[6]:
p q
0 2 5
1 3 6
2 4 7
In [7]:
df.rename({1: 2, 2: 4}, axis='index')
Out[7]:
P Q
0 2 5
2 3 6
4 4 7