Converting Rows In Pandas Dataframe To Columns
I want to convert rows in the foll. pandas dataframe to column headers: transition area 0 A_to_B -9.339710e+10 1
Solution 1:
I think you can first set_index
with column transition
, then transpose by T
, remove columns name by rename_axis
and last reset_index
:
print df.set_index('transition').T.rename_axis(None, axis=1).reset_index(drop=True)
A_to_B B_to_C
0 -9.339710e+10 213.5599
Solution 2:
df = df.T
df.columns = df.iloc[0, :]
df = df.iloc[1:, :]
Post a Comment for "Converting Rows In Pandas Dataframe To Columns"