Make edgelist
Now, you're going to apply the same ideas to making an edge list. Go forth and give it a shot!
As with the previous exercise, run list(G.edges(data=True))[0] in the IPython Shell to get a feel for the edge list data structure before proceeding.
Diese Übung ist Teil des Kurses
Intermediate Network Analysis in Python
Anleitung zur Übung
- Initialize a list called
edgelistto store each edge as a record. - Use a
forloop to iterate over the edges ofG_people. Inside the loop:- Initialize a dictionary called
edgeinfothat shows edge information. - Update the
edgeinfodictionary with the metadata dictionaryd. - Append the
edgeinfodictionary toedgelist.
- Initialize a dictionary called
- Create a pandas DataFrame of the edgelist called
edge_df.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Initialize a list to store each edge as a record: edgelist
edgelist = []
for n1, n2, d in G_people.edges(data=True):
# Initialize a dictionary that shows edge information: edgeinfo
edgeinfo = {'node1':____, 'node2':____}
# Update the edgeinfo data with the edge metadata
____
# Append the edgeinfo to the edgelist
____
# Create a pandas DataFrame of the edgelist: edge_df
edge_df = ____
print(edge_df.head())