我正在Networkx中构建一个图表,通过在一个包含评论人及其评论的社交媒体文章数据库中进行迭代。对于每个注释者,我想将名称添加为节点,并将数据库中的一些值添加为属性。然而,在某些情况下,同一评论者的名字在同一篇文章中出现两次。Networkx随后添加此重复节点,但覆盖原始节点的属性。相反,我想将新属性附加到原始属性上。你知道吗
请参见下面的代码:
for article in articles_with_comments:
G = nx.Graph()
#start populating graph with nodes and attributes
for j, comment in enumerate(article['comments']):
author = (comment['author'])
causal_relations = (comment['causal_relations'])
G.add_node(author)
if causal_relations is not None:
relations = {author:causal_relations}
nx.set_node_attributes(G, relations,'causal_relations')
目前没有回答
相关问题 更多 >
编程相关推荐