I want to make a bipartite graph using networkx. I am following documentation and this previous answer
df = pd.DataFrame({'Name': ['John','John','Aron','Aron','Jeny','Jeny'],
'Movie':['A','B','C','A','Y','Z']})
G = nx.Graph()
G.add_nodes_from(df.Name, bipartite=0)
G.add_nodes_from(df.Movie, bipartite=1)
G.add_edges_from(df.values)
Because my graph is disconnected, i.e.
nx.is_connected(G)
>False
top = nx.bipartite.sets(G)[0]
>AmbiguousSolution
I follow documentation as:
top_nodes = {n for n, d in G.nodes(data=True) if d["bipartite"] == 0}
Z = nx.bipartite.projected_graph(G, top_nodes)
nx.draw(Z)
I get:
I expected: