April 2024
Beginner to intermediate
432 pages
12h 45m
English
Objective: To understand the application of social network analysis in identifying influential users in a marketing context.
Tasks:
Steps:
1. import matplotlib.pyplot as plt2. import networkx as nx3. sna_data = pd.read_csv("/data/Social_Network_Analysis_Data.csv")
This line imports the matplotlib and networkx library and loads the social network data from the CSV file into a pandas DataFrame.
4. G = nx.Graph()5. for index, row in sna_data.iterrows():6. G.add_node(row[‘User’], followers=row[‘Followers’], engagement_rate=row[‘Engagement Rate’])
Here, we create an empty graph using networkx and then add nodes (users) from the DataFrame. Each node is added with attributes ‘followers’ and ‘engagement_rate’. The graph currently has 25 nodes. Here are the attributes for the first five nodes:
Read now
Unlock full access