I am trying to read a file that has like 10000+ entries and with 3 columns. column 1 and 2 are the nodes and column 3 is the time in seconds. I am initially trying to plot a random graph G=(n,m) with the data and later want assign the data from 3rd column in between the two relative nodes. After that i have to count the number of nodes, edges, bridges in that graph. I am some what lost here. if i should first plot the graph and then do the counting or should i count and then plot the graph. Any suggestion will be helpful.
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np
import scipy as sy
import itertools as it
import time
with open("File.txt") as f:
data = f.read()
data = data.split('\n')
node_one = [row[0] for row in data]
node_two = [row[1] for row in data]
def draw_graph(graph):
G = nx.Graph()
#G.add_edges_from([(node_one[0], node_two[1]])
#G.add_edges_from(node_one, node_two)
G.number_of_nodes()
G.number_of_edges()
G.neighbors(edge[0], edge[1])
n = nx.number_connected_components(G)
bridge_count = 0
for edge in G.edges():
if len(set(G.neighbors(edge[0])) & set(G.neighbors(edge[1]))) == 0:
G.remove_edge(edge[0], edge[1])
if nx.number_connected_components(G) > n:
print edge, 'is a bridge'
bridge_count += 1
G.add_edge(edge[0], edge[1])
print number_of_nodes()
print number_edges()
print neighbors()
print bridge_count
The error i am getting here is Traceback (most recent call last): File "edge_bridge.py", line 13, in
node_one = [row[0] for row in data]
IndexError: string index out of range