这段代码我遇到了一些问题
User Follower Relationship Colour_G
0 1 2 23 red
0 1 3 23 red
0 1 20 23 red
0 2 2 1 green
... ... ... ... ... ... ...
13 3 1 22 blue
13 3 4 22 blue
13 3 24 22 blue
我构建的网络是
import networkx as nx
G = nx.from_pandas_edgelist(net, source='User', target='Follower', edge_attr='Relationship')
col_net = net.melt('Colour_G')
nx.draw_networkx_labels(G, pos)
nx.draw_networkx_nodes(G, pos, nodelist= col_net['value'], node_color= col_net['Colour_G'])
nx.draw_networkx_edges(G, pos)
但是在分配颜色时有一些问题,因为当我使用 melt
变量和值包括用户和关注者(所以我有重复)。
颜色是用户的属性,而不是追随者的属性。
在我的示例中,我应该让用户 1 色为红色,2 色为绿色,3 色为蓝色。
我的错误在哪里?