我一直在尝试向我正在创建的此节点添加名称等属性,但收到错误消息。 错误
# add name as a property to each node
# with networkX each node is a dictionary
G.add_node(tweeter_id,'name' = tweeter_name)
G.add_node(interact_id,'name' = interact_name)
这是我得到的错误。 错误信息
File "<ipython-input-31-55b9aecd990d>", line 28
G.add_node(tweeter_id,'name' = tweeter_name)
^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
作为参考,这是整个代码:
import networkx as nx
# define an empty Directed Graph
# A directed graph is a graph where edges have a direction
# in our case the edges goes from user that sent the tweet to
# the user with whom they interacted (retweeted, mentioned or quoted)
#g = nx.Graph()
G = nx.DiGraph()
# loop over all the tweets and add edges if the tweet include some interactions
for tweet in tweet_list:
# find all influencers in the tweet
tweeter, interactions = getAllInteractions(tweet)
tweeter_id, tweeter_name = tweeter
tweet_id = getTweetID(tweet)
# add an edge to the Graph for each influencer
for interaction in interactions:
interact_id, interact_name = interaction
# add edges between the two user ids
# this will create new nodes if the nodes are not already in the network
# we also add an attribute the to edge equal to the id of the tweet
G.add_edge(tweeter_id, interact_id, tweet_id=tweet_id)
# add name as a property to each node
# with networkX each node is a dictionary
G.add_node(tweeter_id, tweeter_name)
G.add_node(interact_id, interact_name)
郎朗坤
明月笑刀无情
呼唤远方
繁华开满天机
随时随地看视频慕课网APP
相关分类