【发布时间】:2018-09-15 22:19:37
【问题描述】:
我正在尝试从CSV file 构建 NetworkX 社交网络图。我正在使用 Networkx 2.1 和 Python 3
我没有运气关注this post,因为我一直收到错误消息:
AttributeError: 'list' object has no attribute '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()
有没有更简化的方法来解决这个问题?数据比较简单。
感谢您的帮助!
【问题讨论】:
-
如果没有MCVE,我们将无法重现错误。您能否上传
csv文件或其中的一部分? -
感谢您的提示,已添加到 Github。 @ducminh 我是 Stack Overflow 的新手。
标签: python-3.x networking decode networkx social