Reputation: 15
I am trying to load in a Multi Directed Graph in NetworkX for a programming assignment with a given txt file, but it is not working. There are no errors, but when I graph the graph and when I do a quick check check to see how many nodes/edges there are it returns 0 for both - which leads me to believe that it is just not loading in the file into the graph at all. Here is my code:
import networkx as nx
def answer_one():
# Your Code Here
G = nx.read_edgelist('email_network.txt', delimiter='\\t', data=[('time', int)], create_using=nx.MultiDiGraph())
return G
answer_one()
Here is a bit of the file I am trying to read in (email_network.txt):
#Sender Recipient time
1 2 1262454010
1 3 1262454010
1 4 1262454010
1 5 1262454010
1 6 1262454010
1 7 1262454010
1 8 1262454010
1 9 1262454010
1 10 1262454010
1 11 1262454010
1 12 1262454010
1 13 1262454010
1 14 1262454010
1 15 1262454010
I looked at Python Reading from a file to create a weighted directed graph using networkx and https://networkx.org/documentation/networkx-1.9/reference/generated/networkx.readwrite.edgelist.read_edgelist.html?highlight=read_edgelist to try to find what parameters I am using wrong but neither of them were that helpful.
Can anyone help me figure out what I am doing wrong/how to load in the file correctly? Thank you :)
Upvotes: 0
Views: 422
Reputation: 15
Update: I found it, it was
G = nx.read_edgelist('email_network.txt', edgetype=int, data=(('weight', int),), create_using=nx.MultiDiGraph())
Upvotes: 0