is there a processor for creating a network graph in Data Science Studio?

219 Views Asked by At

My data has three columns, each representing a node in a tree (a->b->c) and I was curious if there existed a recipe that helped prepare the data for import into Neo4j, NetworkX, or other equivalent graph/network explorer. Thanks in advance for any insight you have regarding the transformation of tabular data into graph format.

1

There are 1 best solutions below

2
Sergey Sosnin On BEST ANSWER

That's a simple python script as an example that can do conversation (if I correctly understand your trouble):

import networkx as nx
import string
str = "a,b,c\nd,e,f\nd,k,j"
print str
lines = string.split(str,'\n')
DG=nx.DiGraph()
for line in lines:
    nodes = line.split(",")
    location = nodes[0]
    manager =  nodes[1]
    report =   nodes[2]
    if (location not in DG):
        DG.add_node(location)
    if (manager not in DG):
        DG.add_node(location)    
    if (report not in DG):
        DG.add_node(location)        
    DG.add_edge(location,manager)
    DG.add_edge(manager,report)

print DG.nodes()
print DG.edges()

This code converts str string to the directed graph.