networkx.enumate\u所有集团忽略组合,不包括

2024-09-28 20:38:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我在spyder中完成了以下代码:

df = nx.from_pandas_adjacency(pd.read_excel(r"path/to/file.xlsx", sheet_name="Sheet4",index_col=0,usecols = "A:BR"))
df1=pd.DataFrame(list(nx.enumerate_all_cliques(nx.Graph(df))))

我有69个对象nx.enumerate_all_cliques从excel文件中找到所有47000个可能的兼容组合。我在这个列表中有一些必须在一起的对象,我想忽略所有不包含all这些对象的组合。我可以列出必须在一起的项目组,因为只有少数项目


Tags: path对象代码frompandasdfreadall
1条回答
网友
1楼 · 发布于 2024-09-28 20:38:26

您可以使用集合来确定所需的所有节点是否都在给定的群组内。下面是一个基于随机图的示例

# Create a random graph.
graph = nx.erdos_renyi_graph(100, .2, seed=0)
# Define the nodes that must be within the clique.
required = {23, 33}
# Iterate over all cliques and only keep the clique if it is a 
# subset of the required nodes.
cliques = [clique for clique in nx.enumerate_all_cliques(graph)
           if required.issubset(clique)]

相关问题 更多 >