AttributeError: 模块“networkx”没有属性“connected_component_subgraphs”

Sat*_*and 11 python error-handling networkx

B = nx.Graph()
B.add_nodes_from(data['movie'].unique(), bipartite=0, label='movie')
B.add_nodes_from(data['actor'].unique(), bipartite=1, label='actor')
B.add_edges_from(edges, label='acted')

A = list(nx.connected_component_subgraphs(B))[0]
Run Code Online (Sandbox Code Playgroud)

当我尝试使用 nx.connected_component_subgraphs(G) 时,我收到以下给定的错误。请帮助解决这个问题。

在数据集中有两个 couns(电影和演员),它是二部图的形式。

我想获得电影节点的连接组件。


----> 1 A = list(nx.connected_component_subgraphs(B))[0]中的AttributeError Traceback(最近一次调用)

AttributeError: 模块“networkx”没有属性“connected_component_subgraphs”

Joe*_*oel 14

这在 2.1 版中已被弃用,并最终在 2.4 版中删除。

请参阅这些说明

(G.subgraph(c) for c in connected_components(G))

或者 (G.subgraph(c).copy() for c in connected_components(G))

  • @CSQGB - 你有问题吗?如果是这样,请开始一个新问题。我无法根据您提供的信息确定问题所在(有向图未实现某些命令,但哪个命令?) (2认同)

小智 8

connected_component_subgraphs 已从 networkx 库中删除。您可以使用弃用通知中描述的替代方法。

对于您的示例,请参考以下代码:

A = (B.subgraph(c) for c in nx.connected_components(B))
A = list(A)[0]
Run Code Online (Sandbox Code Playgroud)