I am new to python and trying to create a bipartite network from a data that looks similar to this:
| User | Text |
| -------- | ------------------- |
| user1 |[ 'abc','xyz','def' ]|
| user2 |[ 'lmo','gf' ] |
| user3 |[ 'lmn','gf' ] |
| user4 |['abc','xyz','def' ] |
When I create a network, nodes that represent text column will have a list as value at node which looks like this:
Instead of having list at node I want to create separate nodes for abc, xyz and so on and then connect those nodes with their respective users. For example user1 will have an edge between abc, xyz and def separately. How can I break the list in such a manner that every value in a list can be made as a separate node. I am stuck here. Thank you for the help in advance.My code so far is as follows:
sub_data = pd.read_csv('E:\\users.csv')
edges = [tuple(x) for x in sub_data[['user','text']].values.tolist()]
B = nx.Graph()
B.add_nodes_from(sub_data['user'].unique(), bipartite=0, label='user')
B.add_nodes_from(sub_data['text'].unique(), bipartite=1, label='hashtag')
B.add_edges_from(edges, label='rating')
left_or_top = sub_data['user'].unique()
pos = nx.bipartite_layout(B, left_or_top)
nx.draw(B,pos,node_color='#A0CBE2',edge_color='#00bb5e',width=1,
edge_cmap=plt.cm.Blues,with_labels=True)