1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Network Analysis in Python

Exercise

Plot number of posts being made over time

Let's recap how you can plot evolving graph statistics from the graph data. First off, you will use the graph data to quantify the number of edges that show up within a chunking time window of td days, which is 2 days in the exercise below.

The datetime variables dayone and lastday have been provided for you.

Instructions

100 XP
  • Define a timedelta of 2 days using the timedelta() function and specifying an argument for the days parameter.
  • Inside the while loop:
    • Filter edges such that they are within the sliding time window. Use a list comprehension to do this, where the output expression is (u, v, d), the iterable is G.edges(data=True), and there are two conditions: if d['date'] is >= curr_day and < than curr_day + td.
    • Append the number of edges (use the len() function to help you calculate this) to n_posts.
    • Increment curr_day by the time delta td.
  • Make a plot of n_posts using plt.plot().