I want convert only first 2 values of the first column of my df into header or turn that values as column/row.
I mean, I have this
0 1 2
Person 7.8 10
Person2 6 11
But I want get this
Person Person2
7.8 6
10 11
CodePudding user response:
Use if first column is not index
use DataFrame.set_index
, transpose, create default index and last remove columns name:
df = df.set_index(0).T.reset_index(drop=True).rename_axis(None, axis=1)
else:
df = df.T.reset_index(drop=True).rename_axis(None, axis=1)