Skip to content
Advertisement

Contracted nodes automatically in Networkx

I have problem, I wish could automatically merge the nodes by inserting an if condition.

I have this dataframe:

JavaScript

I created this graph:

enter image description here

What I would like is to merge the nodes with Weight <15 and not taking the nodes 10.0.11.100,10.0.12.100,10.0.13.100,10.0.14.100 using an if condition.

I tried with this code:

JavaScript

But it does not work. I wish it were all automatic, without me entering the nodes by hand like this::

JavaScript

This is my code:

JavaScript

Thanks

Advertisement

Answer

IIUC, you can use a for loop like this:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement