首页 > 解决方案 > AttributeError:模块“networkx”没有属性“connected_component_subgraphs”

问题描述

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]

我在尝试使用时收到以下给出的错误nx.connected_component_subgraphs(G)

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

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

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-efff4e6fafc4> in <module>
----> 1 A = list(nx.connected_component_subgraphs(B))[0]

AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'

标签: pythonerror-handlingnetworkx

解决方案


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

请参阅这些说明

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

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


推荐阅读