【问题标题】:How to set node attributes after using from_pandas_edgelist networkx使用from_pandas_edgelist networkx后如何设置节点属性
【发布时间】:2018-08-14 04:30:47
【问题描述】:

我已经使用 nx.from_pandas_edgelist 将数据帧加载到 networkx

数据集“main”类似于下面

G = nx.from_pandas_edgelist(main,source = "trader"
,target = "Countertrade",edge_attr = ['product','country','price'])

但是,当我将 G 导出到 graphml 并将其加载到 Gephi 中时,所有节点都没有权重。

在这种情况下,我应该在哪里将我的价格设置为重量?那么节点可以根据权重的值来改变它的大小吗? (A公司将是最大的,因为它已经交易了30个,C公司交易了23个,最后是B公司交易了10个)

感谢您的帮助

【问题讨论】:

  • 表示G['Company A']['Company B']['price'] 的输出是什么?
  • 输出keyerror
  • 嗯。它给了我 10. 检查是否有遗漏的空格等。我看到价格是在每条边上定义的:[degree for node1,node2,degree in G.edges(data=True)]

标签: networkx gephi


【解决方案1】:

似乎最好的方法是创建一个字典并使用 nx.set_node_attributes

【讨论】:

  • 但是由于您没有展示如何使用nx.set_node_attributes 来执行此操作,因此这并不是真正的答案。
猜你喜欢
  • 1970-01-01
  • 2016-05-04
  • 2011-04-28
  • 1970-01-01
  • 1970-01-01
  • 2012-03-27
  • 2013-04-12
  • 2023-03-10
  • 1970-01-01
相关资源
最近更新 更多