Python Forum
How to rename dataframe columns based on the content in an index? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to rename dataframe columns based on the content in an index? (/thread-31815.html)



How to rename dataframe columns based on the content in an index? - ar_mahdavi - Jan-05-2021

Here is my data frame after reading the csv file and splitting it into columns.

[Image: qZQYP.png]

I would like to name my columns based on the content in the 6th row index, then get rid of the first 6 indices, and reset the index from zero. This means that I wish my data to look like this:

[Image: cuwtT.png]

I know how to remove the first 6 rows and rest the indices. But I do not know how to rename the column name based on row 6 at the first step. Can you please help me?

Thanks


RE: How to rename dataframe columns based on the content in an index? - buran - Jan-05-2021

Why not skip 6 rows when reading from the file?


RE: How to rename dataframe columns based on the content in an index? - ricslato - Jun-07-2021

Rename DataFrame

DataFrame.rename({'old_name': 'new_name'}, axis=1, inplace=True)