I am trying to messing with pandas stack and unstack. I was wondering if it is possible to reshape my data in this way.
This is my sample data which I am practicing.
ID,Value1,Value2
1,3,12
1,4,13
1,5,14
1,6,15
1,7,16
2,8,17
2,9,18
2,10,19
2,11,20
And I want to reshape in this way.
ID
1 Index(Extra Column) Value1, value2
1 3 12
2 4 13
3 5 14
4 6 15
5 7 16
2
1 8 17
2 9 18
3 10 19
4 11 20
I tried this
df1 = pd.DataFrame(df[['Value1', 'Value2']], index= df['ID']).stack()
or
df1 = df.set_index(['ID']).stack()
this changes Value1 and Value2 from column to rows which I dont want.
Any Ideas ?