Find the most popular forums day-by-day: I
Great stuff! You're onto the final two exercises - which are really just one long exercise. These will be a good memory workout for your Python programming skills!
We're going to see how many forums took the title of "the most popular forum" on any given time window.
This exercise is part of the course
Intermediate Network Analysis in Python
Exercise instructions
- Instantiate a list to hold the list of most popular forums by day called
most_popular_forums
. - Instantiate a list to hold the degree centrality scores of the most popular forums called
highest_dcs
. - Instantiate new graph called
G_sub
and add in the nodes from the original graphG
using the.add_nodes_from()
method. - Add in edges from the original graph G that fulfill the criteria (which are exactly the same as in the previous exercise).
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import necessary modules
from datetime import timedelta
import networkx as nx
import matplotlib.pyplot as plt
# Instantiate a list to hold the list of most popular forums by day: most_popular_forums
most_popular_forums = ____
# Instantiate a list to hold the degree centrality scores of the most popular forums: highest_dcs
highest_dcs = ____
curr_day = dayone
td = timedelta(days=1)
while curr_day < lastday:
if curr_day.day == 1:
print(curr_day)
# Instantiate new graph: G_sub
G_sub = ____
# Add in nodes from original graph G
____
# Add in edges from the original graph G that fulfill the criteria
G_sub.____([(____, ____, ____) for ____, ____, ____ in ____ if d['____'] >= ____ and d['____'] < ____ + ____])
# CODE CONTINUES ON NEXT EXERCISE
curr_day += td