title: Networkx : How to create graph edges from a csv file?
body: <p>I am trying to create a graph using networkx and so far I have created nodes from the following text files :
  File 1(user_id.txt) sample data : </p>
  
  <pre><code>user_000001
  user_000002
  user_000003
  user_000004
  user_000005
  user_000006
  user_000007
  </code></pre>
  
  <p>File 2(user_country.txt) sample data : contains few blank lines too in case if user didn't enter his country details</p>
  
  <pre><code> Japan
   Peru
   United States
  
   Bulgaria
   Russian Federation
   United States
  </code></pre>
  
  <p>File 3(user_agegroup.txt) data : contains four age groups</p>
  
  <pre><code> [12-18],[19-25],[26-32],[33-39]
  </code></pre>
  
  <p>I have other two files with following sample data for adding edges in the graph</p>
  
  <p>File 4(id,agegroup.txt) </p>
  
  <pre><code>user_000001,[19-25]
  user_000002,[19-25]
  user_000003,[33-39]
  user_000004,[19-25]
  user_000005,[19-25]
  user_000006,[19-25]
  user_000007,[26-32]
  </code></pre>
  
  <p>File 5(id,country.txt)</p>
  
  <pre><code>(user_000001,Japan)
  (user_000002,Peru)
  (user_000003,United States)
  (user_000004,)
  (user_000005,Bulgaria)
  (user_000006,Russian Federation)
  (user_000007,United States)
  </code></pre>
  
  <p>So far I have written following code to draw graphs with only nodes: 
  (Please check the code because <code>print g.number_of_nodes()
  </code> never prints correct no. of nodes though <code>print g.nodes()</code>shows correct no. of nodes.)</p>
  
  <pre><code>import csv
  import networkx as nx
  import matplotlib.pyplot as plt
  g=nx.Graph()
  
  #extract and add AGE_GROUP nodes in graph
  f1 = csv.reader(open("user_agegroup.txt","rb"))
  for row in f1: 
      g.add_nodes_from(row)
      nx.draw_circular(g,node_color='blue')
  
  #extract and add COUNTRY nodes in graph
  f2 = csv.reader(open('user_country.txt','rb'))
  for row in f2:
      g.add_nodes_from(row) 
      nx.draw_circular(g,node_color='red')
  
  #extract and add USER_ID nodes in graph
  f3 = csv.reader(open('user_id.txt','rb'))
  for row in f3:
      g.add_nodes_from(row)
      nx.draw_random(g,node_color='yellow')
  
  print g.nodes()
  plt.savefig("path.png")
  print g.number_of_nodes()
  plt.show()
  </code></pre>
  
  <p>Besides this I can't figure out how to add edges from file4 and file5. Any help with code for that is appreciated. 
  Thanks. </p>