I have the following dataframe:
And I want to change the shape of it, to the following shape:
I only want to change the headers of the dataframe and replace them with the first line and of course, remove the current index and make the column ID as the index of the new dataframe.
P.S.: the data has been imported with pd.read_excel()
and its actual file extention is .xls
.
CodePudding user response:
This should do what you want:
df.columns = df.iloc[0]
df = df.drop(0, axis=0).set_index('ID')