I have a pandas data frame df:
df = pd.DataFrame(data = {'v1': ['b', 'b', 'c', 'a', 'd', 'c', 'd', 'c', 'f', 'e'],
'v2': ['a', 'a', 'd', 'b', 'c', 'e', 'c', 'd', 'g','c'],
'v3': [3.3, 2.9, 3.5, 4.7, 5.1, 1.1, 2.3, 3.4, 4.7, 6.1]})
v1 v2 v3
0 b a 3.3
1 b a 2.9
2 c d 3.5
3 a b 4.7
4 d c 5.1
5 c e 1.1
6 d c 2.3
7 c d 3.4
8 f g 4.7
9 e c 6.1
I want to generate result looks like:
v1 v2 v3
0 b a 3.3
1 b a 2.9
3 a b 4.7
2 c d 3.5
4 d c 5.1
6 d c 2.3
7 c d 3.4
5 c e 1.1
9 e c 6.1
8 f g 4.7
i.e., stack rows with the same pairs of v1 and v2.
v1 = a, v2 = b and v1 = b, v2 = a is not equal(we cannot swap v1 and v2) but they are regarded as in the same group. How can I make it?
Any help appreciated!