Skip to content

Instantly share code, notes, and snippets.

Manik Garg manekgarg

  • Berlin, Germany
Block or report user

Report or block manekgarg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View attribute.py
# 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')
View attribute.py
# 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')
View page_rank.py
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()])
View between_centrality.py
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()])
View community.py
# 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
View add_names.py
# Add information of people
plt.figure(figsize=(22,16))
nx.draw(G, edge_color = '#ced7d9',width = 4, arrowsize = 30, with_labels= True)
View populate_graph.py
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)
@manekgarg
manekgarg / prepare_data.py
Created May 23, 2020
Prepare the basic graph and df for the analysis
View prepare_data.py
# 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
View import.py
import networkx as nx
import pandas as pd
import matplotlib.pyplot as plt
#from utils.pos import pos
from IPython.display import Image
View install.py
pip install networkx
pip install IPython
You can’t perform that action at this time.