Python Forum
How to rename dataframe columns based on the content in an index?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to rename dataframe columns based on the content in an index?
#1
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
Reply
#2
Why not skip 6 rows when reading from the file?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Rename DataFrame

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cannot rename Columns in df tester_V 11 1,318 Aug-27-2023, 06:10 AM
Last Post: perfringo
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,174 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 799 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 1,641 Aug-19-2022, 11:07 AM
Last Post: dm222
  Extracting Specific Lines from text file based on content. jokerfmj 8 2,865 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Remove if similar values available based on two columns klllmmm 1 1,315 Feb-20-2022, 06:55 PM
Last Post: Larz60+
  Rename Files based on XML file klturi421 3 2,135 Oct-22-2021, 07:37 PM
Last Post: klturi421
  Index error - columns vs non-column Vinny 3 4,849 Aug-09-2021, 04:46 PM
Last Post: snippsat
  Apply fillna to multiple columns in dataframe rraillon 2 2,372 Aug-05-2021, 01:11 PM
Last Post: rraillon
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,442 Mar-09-2021, 12:24 PM
Last Post: KMV

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020