Reputation: 167
I am trying to read some dataframe to a networkx graph like this:
bipartGraph = nx.Graph()
bipartGraph.add_edge(618254814, 14337833)
bipartGraph.add_edge(618254882, 12087274)
When I display the edges using the bipartGraph.edges() function, I get the below:
[(14337833, 618254814), (618254882, 12087274)]
So, the direction of the first edge is reversed. I am trying to build a bipartite graph from a dataframe which I need to reuse to build an another graph. Is there any specific property of networkx I am missing?
Upvotes: 0
Views: 1167
Reputation: 23887
At least in networkx 1.11 if your graph is undirected, an edge that is added as (u,v)
may be returned as either (v,u)
or (u,v)
. [I think this may have been changed in version 2.0]. This is because the underlying data structure is a dict, and there is no guarantee that a dict returns values in any particular order: Why items order in a dictionary changed in Python?.
If you really want a direction on your edge, you should make your graph a DiGraph.
Upvotes: 4