import networkx as nx
import pandas as pd
# Create bipartite graph
user_restaurant_graph = nx.Graph()
user_category_graph = nx.Graph()
# Extract unique users, restaurants, and categories
unique_users = subset_review_merged1['user_id'].unique()
unique_restaurants = subset_review_merged1['business_id'].unique()
unique_categories = subset_review_merged['categories'].unique()
# Add nodes with 'bipartite' attribute to user-restaurant graph
user_restaurant_graph.add_nodes_from(unique_users, bipartite='user')
user_restaurant_graph.add_nodes_from(unique_restaurants, bipartite='restaurant')
# Add nodes with 'bipartite' attribute to user-category graph
user_category_graph.add_nodes_from(unique_users, bipartite='restaurant')
user_category_graph.add_nodes_from(unique_categories, bipartite='category')
# Add edges connecting users to restaurants
user_restaurant_edges = [(row['user_id'], row['business_id']) for _, row in subset_review_merged1.iterrows()]
user_restaurant_graph.add_edges_from(user_restaurant_edges)
# Add edges connecting users to categories
user_category_edges = [(row['user_id'], row['categories']) for _, row in subset_review_merged.iterrows()]
user_category_graph.add_edges_from(user_category_edges)
# Add node features to the user-restaurant graph
# Add 'review_count' as a node feature
user_review_count = dict(zip(subset_review_merged1['user_id'], subset_review_merged1['review_count_x']))
restaurant_review_count = dict(zip(subset_review_merged1['business_id'], subset_review_merged1['review_count']))
nx.set_node_attributes(user_restaurant_graph, user_review_count, name='review_count_user')
nx.set_node_attributes(user_restaurant_graph, restaurant_review_count, name='review_count_restaurant')
This is the code for the bipartite graph, the issue i'm having is that when i check for the connectivity of the code, i noticed some where disconnected?