import csv

writer = csv.writer(open('output.csv', 'wb'))
for name, membership in zip(graph.vs['name'], membership):
    pass
Using iGraph in python for community detection and writing community number for each node to CSV