Transforming GDF to JSON
Gephi is an excellent tool to get easy and fast results. However, if we want to present the graph interactively on a website, we need to implement a different kind of visualization. In order to work with the graph in the web, we need to transform our GDF file to JSON format.
Firstly, we need to import the libraries
numpyandjson. For more information about JSON format, refer to Chapter 2, Working with Data.import numpy as np import json
The
numpyfunction,genfromtxt, will obtain only the ID and name from thenodes.csvfile using theusecolsattribute in the'object'format.nodes = np.genfromtxt("nodes.csv", dtype='object', delimiter=',', skip_header=1, usecols=(0,1))Then, the
numpyfunction,genfromtxt, will obtain links with the source node and target node from thelinks.csvfile using theusecolsattribute in the'object'format.links = np.genfromtxt("links.csv", ...