<jupyter_start><jupyter_text>Bipartite projectionsParts of this notebooks are based on or inspired by [<NAME>](https://ericmjl.github.io/)'s code from his amazing course:https://campus.datacamp.com/courses/intermediate-network-analysis-in-python/  Create a dataset<jupyter_code>students = list(range(100))
forums = list(range(7))
# Create dates
dates = pd.date_range('2020-01-01', '2020-12-01', freq = 'd')
rows = []

for date in dates:
    rows.append((
        np.random.choice(students),
        np.random.choice(forums),
        date
    ))
data = pd.DataFrame(rows, columns = ['student', 'forum', 'date'])
data.head()<jupyter_output><empty_output><jupyter_text>Create a graph<jupyter_code># Instantiate a new Graph: G
G = nx.Graph()
# Add nodes from each of the partitions
G.add_nodes_from(data['student'], bipartite='student')
G.add_nodes_from(data['forum'], bipartite='forum')

# Add in each edge along with the date the edge was created
for r, d in data.iterrows():
    G.add_edge(d['student'], d['forum'], date=d['date'])<jupyter_output><empty_output><jupyter_text>Compute projection and centrality<jupyter_code># Get the partitioned nodes
student_nodes = [n for n, d in G.nodes(data=True) if d['bipartite'] == 'student']
forum_nodes = [n for n, d in G.nodes(data=True) if d['bipartite']=='forum']

# Create projected graphs
G_students = nx.bipartite.projected_graph(G, nodes=student_nodes)
G_forum = nx.bipartite.projected_graph(G, nodes=forum_nodes)
# Calculate the degree centrality using nx.degree_centrality: dcs
dcs_stdnt = nx.degree_centrality(G_students)
dcs_forum = nx.degree_centrality(G_forum)

# Plot the histogram of degree centrality values
plt.hist(list(dcs_stdnt.values()), alpha=.5, label='Student')
plt.hist(list(dcs_forum.values()), alpha=.5, label='Forum')
plt.yscale('log') 
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14639397201291712, 'fraction_numerical': 0.011840688912809472, 'mean_word_length': 6.041666666666667, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '40399', 'license': 'MIT', 'n_tokens_mistral': 696, 'n_tokens_neox': 652, 'n_words': 148, 'path': '05_Networkx_-_Bipartite_projections.ipynb', 'repo_name': 'AlxndrMlk/network-analysis', 'size': '1859'}