Unit 40Harnessing Networkx

The networkx module contains essential tools for creating, modifying, exploring, plotting, exporting, and importing networks. It supports simple and directed graphs and multigraphs. You will learn how to construct and modify a network by adding and removing nodes, edges, and attributes; how to calculate various network measures (such as centralities); and how to explore network community structure.

Building and Fixing a Network

Let’s use Wikipedia data[30] to construct and explore a network of nation states, based on the presence (and length) of international land borders. The network graph is undirected; it contains no loops and no parallel edges.

 import​ networkx ​as​ nx
 
 borders = nx.Graph()
 not_borders1 = ...

Get Data Science Essentials 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.