我正在尝试将属性添加到二部网络x图中的一系列节点。一组节点是员工名称;另一组是电影名称。它们看起来像这样:
# This is the set of employees
employees = set(['Pablo',
'Lee',
'Georgia',
'Vincent',
'Andy',
'Frida',
'Joan',
'Claude'])
# This is the set of movies
movies = set(['The Shawshank Redemption',
'Forrest Gump',
'The Matrix',
'Anaconda',
'The Social Network',
'The Godfather',
'Monty Python and the Holy Grail',
'Snakes on a Plane',
'Kung Fu Panda',
'The Dark Knight',
'Mean Girls'])
df = df = pd.read_csv('Employee_Movie_Choices.txt', sep='\t')
#Employee Movie
0 Andy Anaconda
1 Andy Mean Girls
2 Andy The Matrix
3 Claude Anaconda
4 Claude Monty Python and the Holy Grail
从中创建NetworkX图形:
B = nx.from_pandas_dataframe(df, '#Employee', 'Movie')
for e in employees:
nx.set_node_attributes(B, {e: {'type'='employee'}})
for m in movies:
nx.set_node_attributes(B, {m: {'type'='movie'}})
但得到以下错误:
TypeError: set_node_attributes() missing 1 required positional argument: 'values'
我不能解决这个问题。我也试过了:
for e in emplyoees:
nx.set_node_attributes(B, name='type', values='employee')
for m in movies:
nx.set_node_attributes(B, name='type', values='movie')
但是每个for循环都会为每个节点分配其值,即“employee”或“movie”。所以电影会和员工一起被贴上员工的标签,员工也会和电影一起被贴上电影的标签。
非常感谢您的帮助!