Source Code:
(back to article)
import pandas as pd # Create a sample DataFrame df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) # Method 1: using .rename_axis() df = df.rename_axis("Index", axis=0) # Method 2: using .index.name df.index.name = "Index" print(df)
Result:
Report an issue