title: How to create a directed networkx graph from a pandas adjacency matrix dataframe?
body: <p>I have a pandas dataframe of the the following form, <strong>df</strong>,</p>
  
  <pre><code>    A    B    C    D
  A   0   0.5   0.5  0 
  B   1    0    0    0
  C   0.8  0    0   0.2
  D   0    0    1    0
  </code></pre>
  
  <p>I am trying to create a networkx graph from this. I have tried the following variations of code:</p>
  
  <p>A)</p>
  
  <pre><code>G=networkx.from_pandas_adjacency(df)
  G=networkx.DiGraph(G) 
  </code></pre>
  
  <p>B)</p>
  
  <pre><code>G=networkx.from_pandas_adjacency(df, create_using=networkx.DiGraph())
  </code></pre>
  
  <p>However, what ends up happening is that the graph object either:</p>
  
  <p>(For option A) basically just takes one of the values among the two parallel edges between any two given nodes, and <strong>deletes the other one</strong>.</p>
  
  <p>(For option B) takes one of the values among the two parallel edges between any two given nodes, <strong>as the value for both edges</strong>.</p>
  
  <p>For example,</p>
  
  <pre><code>print( list ( filter ( lambda x: x[0]=='A' and x[1] == 'B', list(G.edges.data()) ) ) )
  </code></pre>
  
  <p>and</p>
  
  <pre><code>print( list ( filter ( lambda x: x[0]=='B' and x[1] == 'A', list(G.edges.data()) ) ) )
  </code></pre>
  
  <p>prints 1 and [] for option A.
  prints two 1s for option B.</p>
  
  <p>How do i resolve this issue?</p>