EDITED
I really need help from Networkx/graph experts.
Let us say I have the following data frames and I would like to convert these data frames to graphs. Then I would like to map the two graphs with corresponding nodes based on description and priority attributes.
df1
From description To priority
10 Start 20, 50 1
20 Left 40 2
50 Bottom 40 2
40 End - 1
df2
From description To priority
60 Start 70,80 1
70 Left 80, 90 2
80 Left 100 2
90 Bottom 100 2
100 End - 1
I just converted the two data frames and created a graph (g1, and g2).
And then I am trying to match the nodes based on their description and priority for only once. for example 10/60, 40/100, 50/90 but not 20/70, 20/80, and 70/80. 20 has three conditions to be mapped which are not what I want. Because I would like to map nodes for only once unless I would like to put them as a single node and mark the node as red to differentiate.
A node should only be mapped for only once means, for example, if I want to map 10, it has priority 1 and description Start on the first graph and then find the same priority and description on the second graph. For this, 60 is there. There are no other nodes other than 60. But if we take 20 on the first graph, it has priority 2 and description left. On the second graph, there are two nodes with priority 2 and description left which is 70 and 80. This creates confusion. I cannot map 20 twice like 20/70 and 20/80. But I would like to put them as a single node as shown below on the sample graph.
I am expecting the following result.
To get the above result, I tried it with the following python code.
mapped_list= []
for node_1, data_1 in g1.nodes(data=True):
for node_2, data_2 in g2.nodes(data=True):
if (((g1.node[node_1]['priority']) == (g2.node[node_2]['priority'])) &
((g1.node[node_1]['description']) == (g2.node[node_2]['description']))
):
if (node_1 in mapped_list) & (node_2 in mapped_list): // check of if the node exist on the mapped_list
pass
else:
name = str(node_1) + '/' + str(node_2)
mapped_list.append((data_1["priority"], data_1["descriptions"], node_1, name))
mapped_list.append((data_2["priority"], data_2["descriptions"], node_2, name))
Can anyone help me to achieve the above result shown on the figure /graph/? Any help is appreciated.


