Build a “Panama” Network with Pandas

Pandas is a library that is known to make hard tasks of reading tabular files and manipulating tabular data easy. Pandas takes care of parsing an edge list from a CSV file into a DataFrame; nx.from_pandas_edgelist converts a DataFrame into a graph, making network construction all but trivial.

Now let’s take care of the nodes. Read the three node attribute files into their DataFrames, mark properly (so that you would know later which nodes come from each file), and merge the parts into one DataFrame named all_nodes.

 import​ ​networkx​ ​as​ ​nx
 import​ ​pandas​ ​as​ ​pd
 import​ ​numpy​ ​as​ ​np
 # Read the edge list and convert it to a network
 edges = pd.read_csv(​"all_edges.csv" ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.