0 votes
1 view
in Data Science by (28.1k points)

I currently have a dataframe that looks like this:

image

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:

image

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 (57.5k 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

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


Categories

...