Python Forum

Full Version: How to rename dataframe columns based on the content in an index?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Why not skip 6 rows when reading from the file?
Rename DataFrame

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