问题描述
我想获取 networkx 图的相邻节点的属性。 该图是从 Pandas 数据框生成的,如下所示:
Node Node_Value Neighbor Neighbor_Value
node1 12 ['node2','node10'] [10,NaN]
node2 NaN ['node1','node4'] [12,24]
node3 24 [] []
...
如您所见,有些值为 null (NaN
),有些节点是孤立的(没有邻居)。
例如,我想知道 Node_Value
的属性 (node2
) 与 node1
和 node4
相关联。该属性应该通过取邻居值的平均值 (18) 来给出。同样对于其他节点(node1
和 node3
),它们已经分配的属性应该与邻居的值进行比较以获得它们的平均值(例如,对于 {{1 }},node1
因为我们在数据框中的新列中有一个 (12+10)/3
值)并作为图表中的标签。
这就是我解决问题的方式,但我无法用 python 语言弄清楚。
NaN
在可视化方面,我想我应该扩展 for n in df['Node']: # for each node in Node column to the following
# check each n's neighbor
# if neighbors have value then
# if node has a value,assign to node in Node column the average of all neighbor's values plus its own
# if node has not a value,assign to node in Node column the average of all neighbor's values
和 Neighbor
列。
感谢您的帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)