0

I have checked a lot of melt related questions here but none of them work for what I want to do.

I have this dataframe:

enter image description here

And I want to melt it to this shape:

enter image description here

I have tried a lot of different variations of melt & pivot from stack overflow.

If this is a duplicate question let me know because I wasn't able to find a solution.

My test dataframe:

stack.to_dict()

{'A': {0: 1, 1: 5}, 'B': {0: 2, 1: 6}, 'C': {0: 3, 1: 7}, 'D': {0: 4, 1: 8}}
SCool
  • 3,104
  • 4
  • 21
  • 49
  • 1
    ```melt``` does exactly what you need. For a dataframe ```df``` try ```df.melt()``` – porrrwal Nov 22 '21 at 09:12
  • 1
    @porrrwal Oh wow! That works. I was adding all kinds of arguments to the `melt()` function, that I didn't need to! That's why I was messing it up. I added `id_vars=df.columns` like other stack overflow answers, which seemed to break it. – SCool Nov 22 '21 at 09:14
  • 1
    Use `df.melt(value_name='Number', var_name='Letter')` – jezrael Nov 22 '21 at 09:17

0 Answers0