I have the following framework where I show how many times I saw the transition from Item1 to Item 2. For example, there is one transition from A to B, 2 from A to C, 1 from C to A
Item1 Item2 Moves
1 A B 1
2 A C 2
3 B D 3
4 C A 1
5 C B 5
6 D B 4
7 D C 1
I would like to calculate the difference between the two elements, so the new built Dataframe will be as follows
Item1 Item2 Moves
1 A B 1
2 A C 1
3 B D -1
4 C B 5
5 D C 1
Does anyone know how to do this using Pandas? I think I need to index the first two columns, but I'm brand new in Pandas, and I have a lot of difficulties. Thanks
EDIT There can be no duplicate pairs. For example, you cannot see twice a-> b (but you can, of course, see b-> a)
source
share