I have a dataframe that looks like this:
| name | value 1 | value 2 |
|---|---|---|
| A | 100 | 101 |
| A | 100 | 102 |
| A | 100 | 103 |
| B | 200 | 201 |
| B | 200 | 202 |
| B | 200 | 203 |
| C | 300 | 301 |
| C | 300 | 302 |
| C | 300 | 303 |
And I'm trying to get to this:
| name | value 1 | value 2 | value 3 | value 4 | value 5 | value 6 |
|---|---|---|---|---|---|---|
| A | 100 | 101 | 100 | 102 | 100 | 103 |
| B | 200 | 201 | 200 | 202 | 200 | 203 |
| C | 300 | 301 | 300 | 302 | 300 | 303 |
Here is what i have tried so far;
dataframe.stack()
dataframe.unstack()
dataframe.melt(id_vars=['name'])
I need to transpose the data by ensuring that;
- The first row remains as it is but every subsequent value associated with the same name should be transposed to a coulmn.
- Whereas the second value B (for. ex) should transpose it's associated value as a new value under the column A values, it should not form a separate altogether.