My dataframe looks like this:
Source Target Value Source location Target location
a b 10 [12.3,1.9] [13.5,14.3]
c v 10 [15.3,1.9] [13.5,94.3]
c d 18 [1.4,31.9] [16.6,44.7]
p q 10 [12.3,1.9] [13.5,15.3]
x z 8 [6.3,1.4] [47.5,4.3]
I want to find both the pairs between Source
and Target
. I'm expecting my end result to look like this:
Source Target Value Source location Target location
a b 10 [12.3,1.9] [13.5,14.3]
b a 9 [72.9,18.6] [14.2,31.6]
c e 18 [1.4,31.9] [16.6,44.7]
e c 14 [19.4,5.1] [12.3,23.4]
z x 6 [92.3,1.9] [43.5,14.3]
x z 8 [6.3,1.4] [47.5,4.3]
As you can see, I want to get both the pairs of Source
and Target
- i.e. a-c
as well as c-a
as the two rows.
I tried to research on Stackoverflow but it seems like this question hasn't been answered before. I looked at this and this but they use groupby
to find the count of columns not rearrange the existing dataframe. This one was the closest I got but it returns dataframes on unique combinations of rows not columns.
Any help would be appreciated.