title: Find Connected Components Networkx
body: <p>I need to find the connected nodes in the undirected and weighted graph. I did look up for some suggestions here but no one happens to answer that is related to my problem. These node pairs who also happen to connect with neighbors and every pair while connected spends some time in seconds connected.I am trying to find the connected components and the number of time the same comments connect and for how long (time) do they connect.  </p>
  
  <p>Eg: </p>
  
  <pre><code>Node  Node time
  A      B    34
  A      B    56
  A      C    09
  A      D    5464
  A      C    456
  C      B    36
  C      A    345
  B      C    346
  </code></pre>
  
  <p>So Over all <code>A B C</code> are connected two time </p>
  
  <pre><code>Nodes   connected  time
  [A B C]    1       34+09+36 = 79
  [A B C]    1       56+345+346 = 747
  </code></pre>
  
  <p>Expected output is </p>
  
  <pre><code>Nodes  connected  time 
  [A B C]    2       826
  
  And
  
  Node  connected  time
  [A B]   2         90
  [B C]   2         382
  [A C]   2         354
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>import networkx as nx
  import numpy as np
  from collections import defaultdict
  
  count = defaultdict(int)
  time = defaultdict(float)
  
  data = np.loadtxt('USC_Test.txt')
  
  for line in data:
      edge_list = [(line[0], line[1])]
      G= nx.Graph()
      G.add_edges_from(edge_list)
      components = nx.connected_components(G)
      count['components'] += 1
      time['components'] += float(line[2])
  
  print components, count['components'], time['components']
  </code></pre>
  
  <p>Input:</p>
  
  <pre><code>5454 5070 2755.0
  5070 4391 2935.0
  1158 305  1.0
  5045 3140 48767.0
  4921 3140 58405.0
  5372 2684 460.0
  1885 1158 351.0
  1349 1174 6375.0
  1980 1174 650.0
  1980 1349 650.0
  4821 2684 469.0
  4821 937  459.0
  2684 937  318.0
  1980 606  390.0
  1349 606  750.0
  1174 606  750.0
  5045 3545 8133.0
  4921 3545 8133.0
  3545 3140 8133.0
  5045 4243 14863.0
  4921 4243 14863.0
  4243 3545 8013.0
  4243 3140 14863.0
  4821 4376 5471.0
  4376 937  136.0
  2613 968  435.0
  5372 937  83.0
  </code></pre>
  
  <p>Wrong Output</p>
  
  <p>The output i get is wrong </p>
  
  <pre><code>Last_node_pair  total_count_of_line  total_time  of Entire input data
  </code></pre>
  
  <p>Where as i am supposed to get </p>
  
  <pre><code>[5045 3140 4921]  [number_of_times_same_components_connected]   [total_time_components_connected]
  </code></pre>