Degree distribution

The degree of a node is the number of connections (links) with other nodes. In the case of directed graphs, each node has two degrees—the out-degree and the in-degree. In the undirected graph, the relationship is mutual; then we just have a single degree for each node. In the code listed here, we get the source node and target node references from the links.csv file. Then, we create a single list merging the two lists (target and source). Finally, we get a dictionary (dic) of how many times each node appears in the list, and we plot the result in a bar char using matplotlib.

The links.csv file will look like this:

edgedef>node1 VARCHAR,node2 VARCHAR 23917067,35702006 23917067,629395837 23917067,747343482 23917067,755605075 23917067,1186286815 ...

Get Practical Data Analysis - Second Edition 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.