Reputation: 3642
I have a pandas dataframe
0 1 2
0 pass fail warning
1 50 12 34
I am trying to convert first row as column name something like this
pass fail warning
0 50 12 34
I am currently doing this by renaming the column name
newdf.rename(columns={0: 'pass', 1: 'fail', 2:'warning'})
and then deleting the first row. Any better way to do it .
Upvotes: 15
Views: 29876
Reputation: 481
For the dataframe DF, the following line of code will set the first row as the column names of the dataframe:
DF.columns = DF.iloc[0]
Upvotes: 25