pandas: reshaping the dataset, moving column name as rows

I currently have the following table:

user_id --------- HR(segment_name) ------ observations.

123                1                     0.9
234 .              0 .                   0.78
567                0                     0.99
789                1                     0.89

Now I would like to convert this table to look like the table below:

user_id ---------- segment --------- HR(segment_values) -------- observations
123                HR                   1                         0.9
234                HR                   0                         0.78
567                HR                   0                         0.99
789                HR                   1                         0.89

I probably need to use the pivote table to convert the first table to the second table. Any ideas how to go about this? Thank you :)

Topic reshape data pandas

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.