Edgelist बनाएँ
अब, आप वही विचार एक edge list बनाने में लागू करने जा रहे हैं. आगे बढ़िए और इसे आज़माइए!
जैसा कि पिछले अभ्यास में किया था, आगे बढ़ने से पहले IPython Shell में list(G.edges(data=True))[0] चलाएँ ताकि edge list डेटा स्ट्रक्चर का अंदाज़ा लग सके.
यह अभ्यास पाठ्यक्रम का हिस्सा है
इंटरमीडिएट Network Analysis in Python
अभ्यास निर्देश
edgelistनाम की एक list इनिशियलाइज़ करें जिसमें हर edge एक रिकॉर्ड के रूप में स्टोर हो.G_peopleकी edges पर इटरेट करने के लिए एकforलूप का उपयोग करें. लूप के अंदर:edgeinfoनाम की एक dictionary इनिशियलाइज़ करें जो edge संबंधी जानकारी दिखाए.- मेटाडेटा dictionary
dसेedgeinfodictionary को अपडेट करें. edgeinfodictionary कोedgelistमें append करें.
- edgelist का एक pandas DataFrame बनाएँ जिसका नाम
edge_dfहो.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# 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())