How to rename the columns of a DataFrame
Land Your First Data Science Job
A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.
There is the .columns attribute given by the Pandas library that will give you the current columns of a DataFrame.
You might end up needing to change them.
To do so, you will need to assign a list of new column names to the DataFrame.columns as so:
Be careful to match the correct number of columns that your DataFrame currently have or you will run into an error.
Renaming the index column
In order to rename the index column you will assign a new value to the index.name attribute as so:
Here you are ! You know how to rename both columns and index columns of a DataFrame.
Land Your First Data Science Job
A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.
Related Articles
Continue your learning journey with these related topics
Master Data Science in Days, Not Months 🚀
Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚