xxxxxxxxxx
import pandas as pd
# Create a sample DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
# Display the DataFrame
print(df)
# Change the name of the index
df = df.rename_axis('NewIndexName')
# Display the DataFrame with the updated index name
print(df)
xxxxxxxxxx
df.index = df.index.rename('new_index_name')
# Source: https://pandas.pydata.org/docs/reference/api/pandas.Index.rename.html
xxxxxxxxxx
import pandas as pd
# Create a sample DataFrame
data = {'Index': [1, 2, 3], 'Column1': [4, 5, 6], 'Column2': [7, 8, 9]}
df = pd.DataFrame(data)
# Rename the index column
df.index.name = 'NewIndexColumnName'
# Print the resulting DataFrame
print(df)