Python Reading from a file to create a weighted directed graph using networkx

Viewed 8327

I am new at python and Spyder. I am trying to read from a text file with format into a graph using networkx:

FromNodeId  ToNodeId    Weight
0   1   0.15
0   2   0.95
0   3   0.8
0   4   0.5
0   5   0.45
0   6   0.35
0   7   0.4
0   8   0.6
0   9   0.45
0   10  0.7
1   2   0.45
1   11  0.7
1   12  0.6
1   13  0.75
1   14  0.55
1   15  0.1
...

I want to use Networkx graph format that can store such a large graph(about 10k nodes, 40k edges).

import networkx as nx
import matplotlib.pyplot as plt

g = nx.read_edgelist('test.txt', nodetype=int, create_using= nx.DiGraph())

print(nx.info(g))
nx.draw(g)
plt.show()

When I run this code, nothing happens. I am using Spyder for editing. Could you help? Thanks!

1 Answers
Related