I currently have the dataframe df where I have different Items in the first column, and the other columns are ranking positions (1, 2 and 3) and the values are the correspondent Items in the respective position (of each column)
df = pd.DataFrame(
{'Item': ['I1', 'I2', 'I3', 'I4'],
'1': ['I2', 'I1', 'I4', 'I3'],
'2': ['I4', 'I4', 'I1', 'I2'],
'3': ['I3', 'I3', 'I2', 'I1'],
})
Item 1 2 3
0 I1 I2 I4 I3
1 I2 I1 I4 I3
2 I3 I4 I1 I2
3 I4 I3 I2 I1
I want to have in another dataframe every pair of combinations (Item A and Item B) in the first two columns and a third column with the rank of the Item B correspondent to the Item A in the first dataframe, ordered by rank
Example:
Item A Item B Rank
0 I1 I2 1
1 I1 I4 2
2 I1 I3 3
3 I2 I1 1
4 I2 I4 2
5 I2 I3 3
6 I3 I4 1
7 I3 I1 2
8 I3 I2 3
9 I4 I3 1
10 I4 I2 2
11 I4 I1 3
Can anyone please help?