Created
February 13, 2023 12:37
-
-
Save elliottcordo/e440eb792617ba0f36b7c342550097dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
Graphtype = nx.Graph() | |
with open('result.csv', "r") as data: | |
# skip the header | |
next(data, None) | |
# parse into the graph | |
G = nx.parse_edgelist(data, delimiter=',', create_using=Graphtype) | |
# append the individual subgraph nodes to a list | |
results = [] | |
for x in (G.subgraph(c) for c in nx.connected_components(G)): | |
results.append(x.nodes()) | |
parent = '' | |
with open('output.csv', "w") as output: | |
for group in results: | |
parent = list(group)[0] | |
for match in group: | |
output.write(','.join([parent, match]) + "\n") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment