Мне нужно вывести сообщество каждого узла сети в файл .txt.
Я использую NetworkX вер. 2.1 и Pandas ver. 0.23.4:
import networkx as nx
import pandas as pd
from networkx.algorithms import community
G = nx.barbell_graph(5, 1)
communities_generator = community.girvan_newman(G)
top_level_communities = next(communities_generator)
next_level_communities = next(communities_generator)
sorted(map(sorted, next_level_communities))
#>>> sorted(map(sorted, next_level_communities))
[[0, 1, 2, 3, 4], [5], [6, 7, 8, 9, 10]]
#in this case, 3 different communities (groups) were identified
Мне нужна таблица .txt, похожая на:
NODE COMMUNITY
0 GROUP 1
1 GROUP 1
2 GROUP 1
3 GROUP 1
4 GROUP 1
5 GROUP 2
6 GROUP 3
7 GROUP 3
8 GROUP 3
9 GROUP 3
10 GROUP 3