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
numpy
andjson
. For more information about JSON format, refer to Chapter 2, Working with Data.import numpy as np import json
The
numpy
function,genfromtxt
, will obtain only the ID and name from thenodes.csv
file using theusecols
attribute in the'object'
format.nodes = np.genfromtxt("nodes.csv", dtype='object', delimiter=',', skip_header=1, usecols=(0,1))
Then, the
numpy
function,genfromtxt
, will obtain links with the source node and target node from thelinks.csv
file using theusecols
attribute in the'object'
format.links = np.genfromtxt("links.csv", ...