Home > OS >  how to change the dimentions (reshape) of a dataframe in python?
how to change the dimentions (reshape) of a dataframe in python?

Time:11-22

I have the following dataframe:

actual shape

And I want to change the shape of it, to the following shape:

wanted 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')
  • Related