This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Attribute enrichment of the nodes | |
node_attr = pd.read_csv('/content/quakers_nodelist.csv', index_col = 'Name') | |
node_attr | |
# Add the atribute to the graph G | |
node_attr_d = node_attr.to_dict(orient = 'index') | |
nx.classes.function.set_node_attributes(G, node_attr_d) | |
nx.get_node_attributes(G, 'age') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Attribute enrichment of the nodes | |
node_attr = pd.read_csv('/content/quakers_nodelist.csv', index_col = 'Name') | |
node_attr | |
# Add the atribute to the graph G | |
node_attr_d = node_attr.to_dict(orient = 'index') | |
nx.classes.function.set_node_attributes(G, node_attr_d) | |
nx.get_node_attributes(G, 'age') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pr = nx.pagerank(G) | |
# Plot the the graph again with Page Rank | |
plt.figure(figsize=(25,18)) | |
nx.draw(G, edge_color = '#ced7d9',width = 4, arrowsize = 30, node_color = c_values, font_size =8, | |
alpha = .5, with_labels= True, node_size = [10000*pr[n] for n in G.nodes()]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bc = nx.centrality.betweenness.betweenness_centrality(G) | |
bc | |
# Plot the the graph again with the Between Centrality | |
plt.figure(figsize=(25,18)) | |
nx.draw(G, edge_color = '#ced7d9',width = 4, arrowsize = 30, node_color = c_values, font_size =8, | |
alpha = .5, with_labels= True, node_size = [10000*bc[n] for n in G.nodes()]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import the packages | |
import community | |
from importlib import reload | |
# reload(community) | |
# or use Girvan-Newman algorithm | |
# Assgin the community function to c_values | |
communities = community.best_partition(G.to_undirected(), resolution = .75) | |
c_values = [communities.get(node) for node in G.nodes()] | |
# Plot the the graph again with community using c_values as color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add information of people | |
plt.figure(figsize=(22,16)) | |
nx.draw(G, edge_color = '#ced7d9',width = 4, arrowsize = 30, with_labels= True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
G = nx.from_pandas_edgelist(df, | |
source='Source', | |
target='Target', | |
create_using=nx.DiGraph() | |
) | |
print(nx.info(G)) | |
# Check the closeness of the network | |
nx.average_clustering(G) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an empty graph | |
G = nx.Graph() | |
# Import the dataset as a dataframe | |
df = pd.read_csv('/content/edgelist.csv') | |
# Check the dimension of the data set | |
print(df.shape) | |
df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
#from utils.pos import pos | |
from IPython.display import Image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install networkx | |
pip install IPython |