具有最常见节点的networkx图

问题描述

我想从图G创建一个子图。G具有代表作者的节点和代表共同作者的边。我想提取出版物最多的作者节点的子图。这是严重基于this link的尝试:

# Read in citations as a pandas dataframe and extract Author IDs.
scopus = pd.read_csv(fi)
authors = scopus['Author(s) ID'].dropna()

# Generate a flattened list of all Author IDs.
authors_flat = [b.strip() for a in list(authors) for b in a.split(';')]

# Create all pair combinations of authors from the 'Author(s) ID' field above.
author_connections = list(map(lambda x: list(combinations(x.split(';'),2)),authors))
flat_connections = [item for sublist in author_connections for item in sublist]

# Create a connections graph from the list of connections above.
connx = pd.DataFrame(flat_connections,columns=['From','To'])
connx_graph = connx.groupby(["From","To"]).size().reset_index()
connx_graph.columns = ["From","To","Count"]

# Create a graph from the connections dataframe. 
G = nx.from_pandas_edgelist(connx_graph,source="From",target="To",edge_attr="Count")

# Extract the 100 most common authors.
m = 100
top = pd.DataFrame.from_records(Counter(authors_flat).most_common(m),columns=["Name","Count"])
top_nodes = (n for n in list(G.nodes()) if n in list(top["Name"]))

# Put these most common author nodes into a subgraph.
G_top = G.subgraph(top_nodes)

G_top.number_of_nodes()不为零,但即使我朝G.number_of_nodes()增加m,G_top.number_of_edges()始终等于零。为什么我的G_top子图没有边?有人在上面看到错误吗?非常感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...