Last active
November 13, 2020 09:53
-
-
Save focaalvarez/cc49bba9ab1a4cdf3c09880bbbfaa4ae to your computer and use it in GitHub Desktop.
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 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