networkx 点的属性_在NetworkX中分配节点属性时发生类型错误

我正在尝试将属性添加到二部网络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”。所以电影会和员工一起被贴上员工的标签,员工也会和电影一起被贴上电影的标签。

非常感谢您的帮助!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值