'What is the fastest way to add a lot of nodes/edges to a NetworkX graph programmatically?

I need to quickly create a large NetworkX Graph, with data coming from a query against some database, returning a lot of data. I gear adding nodes and edges one by one would be ridiculously slow. Is there a faster way?



Solution 1:[1]

To add edges, use Graph.add_edges_from.

To add nodes, use Graph.add_nodes_from.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mr.Brawler