शुरू करेंमुफ़्त में शुरू करें

समय के साथ बनाए गए पोस्टों की संख्या का प्लॉट बनाइए

आइए दोहराएँ कि आप ग्राफ डेटा से बदलते हुए ग्राफ आँकड़ों का प्लॉट कैसे बना सकते हैं। सबसे पहले, आप ग्राफ डेटा का उपयोग करके उन edges की गणना करेंगे जो td दिनों की चंकिंग टाइम विंडो के भीतर आती हैं — नीचे दिए अभ्यास में यह 2 दिन है.

आपके लिए datetime वैरिएबल्स dayone और lastday दिए गए हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

इंटरमीडिएट Network Analysis in Python

पाठ्यक्रम देखें

अभ्यास निर्देश

  • timedelta() फंक्शन का उपयोग करके 2 दिनों का timedelta परिभाषित करें और days पैरामीटर के लिए आर्ग्यूमेंट दें.
  • while लूप के अंदर:
    • edges को ऐसे फ़िल्टर करें कि वे स्लाइडिंग टाइम विंडो के भीतर हों। इसके लिए लिस्ट कॉम्प्रिहेंशन का उपयोग करें, जहाँ आउटपुट एक्सप्रेशन (u, v, d) है, इटेरेबल G.edges(data=True) है, और दो कंडीशन्स हैं: अगर d['date'] >= curr_day हो और < curr_day + td से कम हो.
    • edges की संख्या (यह निकालने में मदद के लिए len() फंक्शन का उपयोग करें) को n_posts में append करें.
    • curr_day को time delta td से इंक्रीमेंट करें.
  • plt.plot() का उपयोग करके n_posts का प्लॉट बनाइए.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Import necessary modules
from datetime import timedelta  
import matplotlib.pyplot as plt

# Define current day and timedelta of 2 days
curr_day = dayone
td = ____

# Initialize an empty list of posts by day
n_posts = []
while curr_day < lastday:
    if curr_day.day == 1:
        print(curr_day) 
    # Filter edges such that they are within the sliding time window: edges
    edges = [(____, ____, ____) for u, v, d in ____ if d['date'] >= ____ and d['date'] < ____ + ____]
    
    # Append number of edges to the n_posts list
    ____
    
    # Increment the curr_day by the time delta
    ____ += ____
    
# Create the plot
plt.plot(____)  
plt.xlabel('Days elapsed')
plt.ylabel('Number of posts')
plt.show()  
कोड संपादित करें और चलाएँ