Reading Text File of Graph data using NetworkX
<p>I'm very new to networkX. So having problem in very basic things.</p>

<p>I've network data in the text file in following format:</p>

<pre><code>InNode  OutNode

 N1       N5
 N2       N4
 N3       N6
 N2       N2
 N4       N7
</code></pre>

<p>My questions are the following:</p>

<p>1) How to read the data using networkX, so that I can get the nodes and edges between the graph?</p>

<p>2) How to calculate the self-edge of the network (N2, N2)?</p>

<p>I tried the following code. But it's not giving me the right answer.</p>

<pre><code>import matplotlib
import networkx as net
import urllib
import csv


g = net.Graph()

f1 = csv.reader(open("data.txt","rb"))

for row in f1: 
    g.add_nodes_from(row)

len(g)

g.number_of_nodes()
</code></pre>