'How to transform (unpivot & pivot) python data frame

I have python pandas data frame as listed below which want to transformed

Current Data frame

Line Domain B_Domain Rec_Res Rec_CR Rec_PR Revisions_Res Revisions_CR Revisions_PR Net_Res Net_CR Net_PR Rec_All Revisions_All Net_All Total_All
IG N Australia -0.003626488 -0.029834651 0.201807046 -0.114452039 -0.000543174 -0.03666427 -0.033461139 0.087355007 -0.037207445 0.02352396

Expected Data frame after transformation :

line Domain B Domain Type Res CR PR All
IG N Australia Rec -0.003626488 -0.029834651 -0.033461139
IG N Australia Revisions 0.201807046 -0.114452039 0.087355007
IG N Australia Net -0.000543174 -0.03666427 -0.037207445
IG N Australia Total 0.02352396

thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source