Work with Edge Lists and Node Dictionaries

You do not have to mess with matrices, NumPy, and Pandas to bulk move data between your code and NetworkX networks. You can use edge lists and node dictionaries.

Edge Lists

An edge list is a list of 3-tuples containing the start node, end node, and a dictionary of edge attributes for each edge. You can obtain it from an existing network by calling nx.to_edgelist or construct it yourself and feed as the parameter to nx.from_edgelist to produce a new network.

 edges = nx.to_edgelist(G)
 F = nx.from_edgelist(edges)
 print​(F.edges(data=True))
<= [('Born', 'Married', {'weight': 1}), ('Married', 'Elected Rep',
  {'weight': 1}), ('Elected Pres', 'Died', {'weight': 1}),
  ('Died', 'Born', {'weight': 0.1}), ...

Get Complex Network Analysis in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.