If you want to only rename specific column names in a Python pandas DataFrame, you can make use of the DataFrame.rename() function as follows.
Code Example:import pandas as pd
df = pd.DataFrame({'Open Price': [14, 22, 45],
'High': [16, 22, 46],
'Low': [12, 20, 41],
'Close': [15, 21, 42]})
df = df.rename(columns={'High': 'Highest Price',
'Low': 'Lowest Price',
'Close': 'Closing Price'})
print(df)
As you may see I have renamed only 3 columns specifically by providing a dictionary where the keys are the current column names and the values are the desired new column names, I have not changed the "Open Price" column as it looks good already!

Documentation: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.rename.html
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!