I have tried a bunch of different ways to do this in Python, and I'm sure i'm missing something. My data is like this:
Date | Stock 1 | Stock 2 | Stock 3
11-30-86 2.45 0.47021 1.45879
12-31-86 -2.57 1.09626 -2.67784
01-31-87 13.5 9.33911 11.14448
02-28-87 3.99 4.63777 5.96181
What I'd like to do is transpose the data BY stock name (column name) and have it rendered like this:
Stock Name | Date | Return
Stock 1 11-30-86 2.45
Stock 2 11-30-86 0.47021
Stock 3 11-30-86 1.45879
Stock 1 12-31-86 -2.57
Stock 2 12-31-86 1.09626
Stock 3 12-31-86 -2.67784
Stock 1 01-31-87 13.5
Stock 2 01-31-87 9.33911
Stock 3 01-31-87 11.14448
Stock 1 02-28-87 3.99
Stock 2 02-28-87 4.63777
Stock 3 02-28-87 5.96181
I've trying different permutations of Pandas pivot/unpivot and transpose but I can't seem to get this working - I only ever get the entire table pivoted, where I want to use the different column names are BY groups and get the resulting single column.
What am I missing?