I am struggling a bit with some pandas reshaping. I have this dataframe:
+---------+----------+----------+----------+------------+
| Column1 | Sample 1 | Sample 2 | Sample 3 | Identifier |
+---------+----------+----------+----------+------------+
| 11 | 1.0 | 1.1 | 1.3 | ABC |
| 12 | 2.0 | 1.9 | 2.2 | ABC |
| 13 | 6.7 | 2.3 | 8.9 | ABC |
| 11 | 1.0 | 1.1 | 1.3 | DEF |
| 12 | 2.0 | 1.9 | 2.2 | DEF |
| 13 | 6.7 | 2.3 | 8.9 | DEF |
+---------+----------+----------+----------+------------+
And I would like to reshape it to this:
+---------+--------+------------+--------+
| Column1 | Sample | Identifier | Result |
+---------+--------+------------+--------+
| 11 | 1 | ABC | 1.0 |
| 11 | 2 | ABC | 1.1 |
| 11 | 3 | ABC | 1.3 |
| 11 | 1 | DEF | 1.0 |
| 11 | 2 | DEF | 1.1 |
| 11 | 3 | DEF | 1.3 |
| 12 | 1 | ABC | 2.0 |
| 12 | 2 | ABC | 1.9 |
| 12 | 3 | ABC | 2.2 |
| ... | | | |
+---------+--------+------------+--------+
Essentially, it has been given in a really horrible excel sheet with repeated samples as a collection of columns.
Ideally I want Column1 as the eventual column headers, with Sample and Identifier as the index and Result as values, but I know I need it in the shape above to do that relatively straighforward with df.pivot() (just in case you know a way to go from my source to the eventual destination a bit easier than my way).