在Python中编写csv时的对象类型

时间:2018-06-24 17:40:23

标签: python igraph

我正在尝试使用igraph为每个节点找到最佳社区数量,并在这里Using iGraph in python for community detection and writing community number for each node to CSV

找到了一个不错的答案

我尝试了他提供的代码,但是遇到了错误

TypeError: a bytes-like object is required, not 'str'

这是我使用的代码

import igraph
import csv

g = igraph.Graph.Read_Ncol('data.txt')
dendrogram = g.community_edge_betweenness()
clusters = dendrogram.as_clustering()
membership = clusters.membership

writer = csv.writer(open("output.csv", "wb"))
for name, membership in zip(g.vs["name"], membership):
    writer.writerow([name, membership])

0 个答案:

没有答案