我正在尝试从一个CSV文件中构建一个NetworkX社交网络图。我正在使用Networkx 2.1和Python 3。
我按照这篇帖子的步骤进行操作,但是没有成功,因为我不断收到以下错误:
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()
有没有更简单的方法来解决这个问题?数据相对来说比较简单。
谢谢你的帮助!
csv
文件或其中的一部分吗? - ducminh