I have a pandas dataframe of the form df,
Batch_ID Product_ID
1 A
1 B
1 C
2 B
2 B
2 C
2 C
3 B
3 B
3 C
4 C
4 D
5 D
I would like to get an edge list from this, essentially a new dataframe edge_list_df (which I cant then convert to networkx object) of the form,
Source Target Weight
A B 1.0
A C 1.0
A D 0.0
B C 3.0
B D 0.0
C D 1.0
Note that I have given a number of different possibilities in the example to ensure my question is clear. For instance, the counter does not increase two times even though for Batch_ID=2 the B-C combination occurs twice.
What is the most efficient way to achieve this?