G = nx.Graph()
for line in data:
    a, b, time = line
G.add_edge(a, b)
results = defaultdict(lambda : list([0, 0.0]))
components = nx.connected_components(G)
component_map = {}
component_stats = defaultdict(lambda : list([0, 0.0]))
edge_stats = defaultdict(lambda : list([0, 0.0]))
for nodes in components:
    for node in nodes:
        component_map[int(node)] = tuple(nodes)
for a, b, time in data:
    component_stats[component_map[a]][0] += 1
component_stats[component_map[a]][1] += time
if len(component_map[a]) > 2:
    edge_stats[a, b][0] += 1
edge_stats[a, b][1] += time
for nodes, (count, time) in component_stats.items():
    print(sorted([int(n) for n in nodes]), count, time)
print() 
for nodes, (count, time) in edge_stats.items():
    pass
Find Connected Components Networkx