Python Pandas Library rename function

27 June 2023 377 Reading time: 20 second

The rename function in the Pandas library is used to rename the columns or indexes of a DataFrame. This function can be used to change the name of a specific column or index or rename the names of all columns or indexes.


import pandas as pd

# Rename the column 'old_name' to 'new_name'
df.rename(columns={'old_name': 'new_name'}, inplace=True)
print(df)

Similar articles