如何解决具有最常见节点的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 举报,一经查实,本站将立刻删除。