Skip to content

Instantly share code, notes, and snippets.

@focaalvarez
Last active November 13, 2020 09:53
Show Gist options
  • Save focaalvarez/cc49bba9ab1a4cdf3c09880bbbfaa4ae to your computer and use it in GitHub Desktop.
Save focaalvarez/cc49bba9ab1a4cdf3c09880bbbfaa4ae to your computer and use it in GitHub Desktop.
import pandas as pd
import networkx as nx
import netwulf as wulf
import community as community_louvain
df = pd.read_csv('YOUR RELATIONS FILE.csv')
#Filter the user following accounts to a smaller subset of accounts that follow me
df=df[df['following'].isin(my_followers)]
#Create Network Object
G=nx.from_pandas_edgelist(df, 'user', 'following')
#Find sub-communities with the Louvain method
partition = community_louvain.best_partition(G)
#Add sub-communities as Groups
nx.set_node_attributes(G, partition, "group")
#Find most influential nodes of the network
top_influencers_nodes=nx.voterank(G,number_of_nodes=15)
#VISUALISE
stylized_network, config = wulf.visualize(G,config=netwulf_config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment