df.index = df.index.rename('new_index_name')
# Source: https://pandas.pydata.org/docs/reference/api/pandas.Index.rename.html
# For index name:
df = df.rename(index={'old_name': 'new_name'})
# or
df.index = df.index.rename('new_name')
# or
df.index.rename('new_name', inplace=True)
# For column name:
df = df.rename(columns={'old_name': 'new_name'})
#
df.columns = df.columns.rename('new_name')
# or
df.columns.rename('new_name', inplace=True)
df.rename(index={'alpha': 'mu'})
import pandas as pd
# Sample DataFrame
df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
# Changing columns name with index number
su = df.rename(columns={df.columns[1]: 'new'})
# Display
display(su)
df.rename({1: 2, 2: 4}, axis='index')