Removing edges
There will likely be times when you will need to remove edges. This can be useful, not just for cleaning networks but also for simulating attacks, or for identifying cliques and communities. For instance, I often use what is called minimum cuts or minimum edge cuts to find the fewest number of edges that will split a network into two pieces. I use this for community detection, and also to spot emerging trends on social media.
With the Alice in Wonderland network, there are no edges that we need to remove, so I will first show you how to remove some edges, and then I’ll show you how to put them back:
- You can remove edges one at a time:
G.remove_edge(
'Dormouse'
, 'Tillie') - Alternatively, you can remove several at a time:
drop_edges = [('Dormouse', 'Tillie'), ('Dormouse', 'Elsie'), ('Dormouse', 'Lacie')]
G.remove_edges_from(drop_edges)
How does this look when visualized...