I have a pandas Dataframe that looks like this:
pid | fid | FirstReasonName | FirstReasonValue | SecondReasonName | SecondReasonValue |
---|---|---|---|---|---|
1 | ‘x’ | ‘a’ | 3 | ‘b’ | 8.2 |
2 | ‘y’ | ‘c’ | 8 | ‘d’ | 7 |
Now I want to unpivot it on pid
and fid
so that it would become this:
pid | fid | Reason | Value |
---|---|---|---|
1 | ‘x’ | ‘a’ | 3 |
1 | ‘x’ | ‘b’ | 8.2 |
2 | ‘y’ | ‘c’ | 8 |
2 | ‘y’ | ‘d’ | 7 |
How do I do this?