Examples
import numpy as np
import pandas as pd
df = pd.DataFrame({"P": [2, 3, 4], "Q": [5, 6, 7]})
Change the row labels.
df.set_axis(['p', 'q', 'r'], axis='index', inplace=False)
Change the column labels:
df.set_axis(['1', '2'], axis='columns', inplace=False)
Let update the labels inplace:
df.set_axis(['I', 'II'], axis='columns', inplace=True)
df