问题描述
我正在尝试创建一个定向贸易网络,并且我希望节点大小能够反映每个国家/地区(即节点)的相对市场份额。这是基于双边出口数据,所以我需要计算每个国家的出口总额。但我要么一直得到总计(所以是每条边的总和),要么最终得到 0。
这是我正在努力处理的代码:
totexp = {}
# Calculate total exports of each country in the network
for exp in G.nodes():
tx=sum([float(g) for (f,g,exp) in G.edges.data('exports',exp)])
totexp[exp] = tx
avgexp = np.mean(tx)
nx.set_node_attributes(G,totexp,'totexp')
#Use the results later for the node's size in the graph
node_size = [float(G.nodes[v]['totexp'])/avgexp for v in G]
print(node_size)
数据框只有三列:exporter、importer 和 export values。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)