I have this code which runs perfectly fine.
G = nx.Graph()
num_row = len(attr_df)
keys = attr_df.columns
attrs = {}
for i in range(num_row):
G.add_node(attr_df['MATNR'][i], PSTAT= attr_df['PSTAT'][i])
and if I was to call
G.nodes()
I would get a long list of all the nodes.
But when I call
G.node[0]
to look at an individual node and its properties, I get:
AttributeError: 'Graph' object has no attribute 'node'
CodePudding user response:
G.nodes() is a method that returns a NodeView object. There is no value being created called G.node that can be iterated over.
You can cast NodeView to a list like this list(NodeViewObj)
, and therefore access the first element like so:
list(G.nodes())[0]
The documentation details this