使用 from_pandas_edgelist 函数将 edge_keys 分配给 networkx 多重图会返回错误
I am trying to recreate the following script from the networkx文档:
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(),)
当我执行此操作时,我没有得到预期的图表,我会收到以下错误:
TypeError: from_pandas_edgelist() got an unexpected keyword argument 'edge_key'
我在删除 edge_key =“ my_edge_key”后尝试运行它em>零件和图的生成很好。 但是事实是,我正在研究一个大型多编码,边缘具有相同的启动和结尾对。我需要为我的图形边缘分配键,因为我计划通过其正在处理的图形来删除其键的特定边缘。因此,我想知道,我是否在分配边键时做错了什么。还是这是一个过时的功能,现在有一种更好的方法可以做到这一点?如果是这样,有人可以指导我吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更新
networkx
才能使用edge_key
参数。如您所见有此参数。 In contrast the latest version (as you have also seen in the docs) has the parameter, see 在这里。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.