I am trying to use igraph to find the optimal number of communities for each nodes and found a good answer here Using iGraph in python for community detection and writing community number for each node to CSV
I tried the code he provided but run into error
TypeError: a bytes-like object is required, not 'str'
Here's the code I used
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])