小编Mel*_*ssa的帖子

在Python 3中从CSV文件创建Networkx图

我正在尝试从CSV文件构建NetworkX社交网络图。我正在使用Networkx 2.1和Python 3

我没有运气就遵循了这篇文章,因为我不断收到错误:AttributeError:'list'对象没有属性'decode'。

我的目标是使权重显示的边缘较粗,而权重较高。

到目前为止,这是我的代码:

import networkx as nx
import csv

Data  = open('testest.csv', "r", encoding='utf8')
read = csv.reader(Data)
Graphtype=nx.Graph()   # use net.Graph() for undirected graph

G = nx.read_edgelist(read, create_using=Graphtype, nodetype=int, data=(('weight',float),))

for x in G.nodes():
      print ("Node:", x, "has total #degree:",G.degree(x), " , In_degree: ", G.out_degree(x)," and out_degree: ", G.in_degree(x))   
for u,v in G.edges():
      print ("Weight of Edge ("+str(u)+","+str(v)+")", G.get_edge_data(u,v))

nx.draw(G)
plt.show()
Run Code Online (Sandbox Code Playgroud)

有没有更简单的方法来解决这个问题?数据相对简单。

谢谢您的帮助!

social networking decode networkx python-3.x

4
推荐指数
1
解决办法
7243
查看次数

标签 统计

decode ×1

networking ×1

networkx ×1

python-3.x ×1

social ×1