my data is in the following format
x = pd.DataFrame([
{'date': '2011-01-01', 'col1': '1','col2': '5', 'A_Q': '1', 'A_W': 'aa', 'B_Q': '2', 'B_W': 'zz'},
{'date': '2011-01-02', 'col1': '1','col2': '9', 'A_Q': '-1', 'A_W': 'bb', 'B_Q': '3', 'B_W': 'rr'},
{'date': '2011-01-03', 'col1': '3','col2': '3', 'A_Q': '0', 'A_W': 'cc', 'B_Q': '4', 'B_W': 'vv'},
{'date': '2011-02-04', 'col1': '4','col2': '1', 'A_Q': '3', 'A_W': 'dd', 'B_Q': '5', 'B_W': 'gg'},
])
date col1 col2 A_Q A_W B_Q B_W
0 2011-01-01 1 5 1 aa 2 zz
1 2011-01-02 1 9 -1 bb 3 rr
2 2011-01-03 3 3 0 cc 4 vv
3 2011-02-04 4 1 3 dd 5 gg
I would like to reshape the dataframe using melt or similar functions, with two output value columns. Any ideas on how to do this without splitting the input array?
date col1 col2 VAR Q W
0 2011-01-01 1 5 A 1 aa
1 2011-01-01 1 5 B 2 zz
2 2011-01-02 1 9 A -1 bb
3 2011-01-02 1 9 B 3 rr
4 2011-01-03 3 3 A 0 cc
5 2011-01-03 3 3 B 4 vv
6 2011-01-04 4 1 A 3 dd
7 2011-01-04 4 1 B 5 gg