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
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 632 Mar-09-2021, 12:24 PM
Last Post: KMV
  Pandas dataframe without index tgottsc1 3 1,513 Feb-01-2021, 05:29 PM
Last Post: snippsat
  How to sum across variable columns in a dataframe rennerom 2 617 Jan-31-2021, 05:44 PM
Last Post: rennerom
  How to split dataframe object rows to columns Mekala 1 456 Nov-12-2020, 04:18 PM
Last Post: michael1789
  convert list to five columns dataframe in sequence tonycat 2 722 Sep-29-2020, 06:47 AM
Last Post: tonycat
  How to melt dataframe multiple columns to one column Mekala 1 695 Sep-24-2020, 08:32 PM
Last Post: scidam
  Concatenate two files with different columns into one dataframe moralear27 1 614 Sep-11-2020, 10:18 PM
Last Post: moralear27
  How to map dataframe based on two columns Mekala 0 1,540 Aug-29-2020, 07:36 AM
Last Post: Mekala
  Cmparing columns in dataframe Rejoice 0 455 Aug-17-2020, 08:48 PM
Last Post: Rejoice
  Do Calculation between Rows based on Column values - Pandas Dataframe ahmedwaqas92 0 1,059 Jan-28-2020, 07:06 AM
Last Post: ahmedwaqas92

Forum Jump:

User Panel Messages

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