python: how to make a pd dataframe header's second component the top row

603 views python

I have a dataframe (df) which looks like the following:

                               0        1        2      3       4   5
s4-e1-p1-cohex.wav             0.0      0.0      0.0    Male    No  0.0
s4-e1-p2-thev-buckle.wav       50000    0.51     98039  Male    Yes 1
s4-e10-p1rly-newlyweds.wav     0        0        0      Female  No  0
s4-e10-p2-ks-away.wav          150000   0.2      750000 Male    Yes 1

currently, this dataframe's header is the first two rows:

#[(0, 0.0), (1, 0.0), (2, 0.0), (3, 'Male'), (4, 'No'), (5, 0.0)]

I am wondering how I can move the second row in this printed out dataframe to the top row in the panda dataframe. In other words, the row printed below is not in the pd dataframe and I want to include that as the top row of the dataframe (s4-e1-p1-cohex.wav is not in the column names nor in row names):

s4-e1-p1-cohex.wav             0.0      0.0      0.0    Male    No  0.0

I have to tried to search around but did not find an answer to this weird formatting. I know I can just make the column names a different vector and insert it back to the dataframe but I am wondering if there are other ways that's less convoluted.

answered question

1 Answer


Try this


to remove the first row.

posted this

Have an answer?


Please login first before posting an answer.