Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (50.2k points)

I currently have a dataframe that looks like this:


I'm looking for a way to delete the header row and make the first row the new header row, so the new dataframe would look like this:


I've tried stuff along the lines of if 'Unnamed' in df.columns: then make the dataframe without the header df.to_csv(newformat,header=False,index=False) but I don't seem to be getting anywhere.

1 Answer

0 votes
by (108k points)

First, you have to grab the first row for the header then take the data less the header row after that set the header row as the df header

new_header = df.iloc[0] 

df = df[1:] 

df.columns = new_header

If you wish to Learn more about Pandas visit this Pandas Tutorial.

If you are interested to learn Python from Industry experts, you can sign up for this Python Certification Course by Intellipaat.

Browse Categories