I am trying to recreate the following script from the networkx documentation:
edges = pd.DataFrame(
{
"source": [0, 1, 2, 0],
"target": [2, 2, 3, 2],
"my_edge_key": ["A", "B", "C", "D"],
"weight": [3, 4, 5, 6],
"color": ["red", "blue", "blue", "blue"],
})
G = nx.from_pandas_edgelist(
edges,
edge_key="my_edge_key",
edge_attr=["weight", "color"],
create_using=nx.MultiGraph(),)
When I do this, instead of getting the expected graph, I get the following error:
TypeError: from_pandas_edgelist() got an unexpected keyword argument 'edge_key'
I have tried running it after removing the edge_key="my_edge_key", part and the graph is generated just fine. But the thing is, I am working on a large multigraph with edges having the same start and end node pairs. I need to assign keys to my graph edges because I plan to remove particular edges by their keys for the graph that I am working on. So I was wondering, if I was doing something wrong in assigning the edge keys. Or is this an outdated function and there is now a better way to do this? If so, could someone please direct me?
You need to update
networkx
to be able to use theedge_key
parameter. As you can see here the version 2.4 did not had this parameter. In contrast the latest version (as you have also seen in the docs) has the parameter, see here.