I have two working scripts, but neither of them as I would like. The sample data file I have is in a file called 'file2.txt'
The first script I have works and produces a graph I want, however the input comes from StringIO (i want from csv in chunks)
To try and read the data from a large data file i want to read in chunks, so got to the following point which is in the right direction but the output graph is wrong...
First Graph (what i want)
Second Graph (dont understand why it is like this...)
Thanks for any help!
Code:
Email,IP,weight,att1
jim.bob@junk.com,192.168.0.1,2,4
steve.bob@mc.com,192.168.0.1,3,4
mary.bob@video.com,192.168.0.25,4,4
The first script I have works and produces a graph I want, however the input comes from StringIO (i want from csv in chunks)
Python:
import StringIO
import networkx as nx
import matplotlib.pyplot as plt
data = StringIO.StringIO("""
jim.bob@junk.com,192.168.0.1,2,4
steve.bob@mc.com,192.168.0.1,3,4
mary.bob@video.com,192.168.0.25,4,4
""")
G = nx.read_edgelist(data, delimiter=',', nodetype=str, data=[('weight',int),('att1',int)])
for e in G.edges():
print e
pos = nx.spring_layout(G,scale=1)
node_labels = nx.get_node_attributes(G,'state')
nx.draw_networkx_labels(G, pos, labels = node_labels)
edge_labels = nx.get_edge_attributes(G,'state')
nx.draw_networkx_edge_labels(G, pos, labels = edge_labels)
nx.draw(G,pos, with_labels=True)
plt.savefig('this.png')
plt.show()
To try and read the data from a large data file i want to read in chunks, so got to the following point which is in the right direction but the output graph is wrong...
Python:
import matplotlib.pyplot as plt
import pandas as pd
import networkx as nx
G = nx.DiGraph()
for d in pd.read_csv("file2.txt",sep='\s+', header=None, names=['A', 'B'], chunksize=10000):
G.add_edges_from([tuple(x) for x in d.values])
for e in G.edges():
print e
pos = nx.spring_layout(G,scale=1)
nx.draw(G,pos, with_labels=True)
plt.savefig('this.png')
plt.show()
First Graph (what i want)
Second Graph (dont understand why it is like this...)
Thanks for any help!