0 votes
1 view
in Data Science by (38.8k 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 (83.8k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !