O'Reilly logo

Practical Data Analysis by Hector Cuesta

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

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, so we just have a single degree for each node. In the following code snippet we get the source node and target node references from the file links.csv. Then we create a single list to merge 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 chart using matplotlib.

The file links.csv will look as follows:

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

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