Examples
DataFrame.rename supports two calling conventions:
import numpy as np
import pandas as pd
df = pd.DataFrame({"P": [2, 3, 4], "Q": [5, 6, 7]})
df.rename(columns={"P": "p", "Q": "r"})
Rename index using a mapping:
df.rename(index={0: "x", 1: "y", 2: "z"})
Cast index labels to a different type:
df.index
df.rename(index=str).index
Using axis-style parameters:
df.rename(str.lower, axis='columns')
df.rename({1: 2, 2: 4}, axis='index')