O'Reilly logo

Complex Network Analysis in Python by Dmitry Zinoviev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required