When learning Networkx, you encounter an error when viewing node attributes:
attributeerror: ‘graph’ object has no attribute ‘node’
G= nx.Graph(name='undirected graph',data=2022) # Create undirected graph
G.add_nodes_from([1,2,3,4,5]) # Add nodes to the graph using the list
G.add_node(6,name='F',weight=12)
print(G.node[6]['name']) # Check the other attributes of the node according to its ID
The reason is that the lower version of Networkx has the node attribute, while the higher version does not use the node attribute
correction method 1: just change the node attribute to nodes
the correct code is as follows:
G= nx.Graph(name='undirected graph',data=2022) # Create undirected graph
G.add_nodes_from([1,2,3,4,5]) # Add nodes to the graph using the list
G.add_node(6,name='F',weight=12)
print(G.nodes[6]['name']) # Check the other attributes of the node based on its ID
Correction 2: reinstall the lower version of Networkx
PIP install: PIP install Networkx = = 2.3
Read More:
- [Solved] Operator Not Allowed In Graph Error & Attribute Error Tensor object has no attribute numpy
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘map‘
- AttributeError: DatetimeProperties object has no attribute
- [Solved] vpython: AttributeError: ‘box‘ object has no attribute ‘idx‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘tolist‘
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] AttributeError WriteOnlyWorksheet object has no attribute cell
- [Solved] AttributeError: ‘PngImageFile‘ object has no attribute ‘imshow‘
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘astype‘
- [Solved] AttributeError: ‘DataParallel‘ object has no attribute ‘save‘
- How to Solve attributeerror: ‘list’ object has no attribute ‘shape‘
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [Solved] AttributeError: ‘HTMLWriter‘ object has no attribute ‘_temp_names‘
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [2021-10-05] Python Error: AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] Paramiko error: AttributeError: ‘NoneType’ object has no attribute ‘time’
- [Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute
- [Solved] AttributeError: DataFrame object has no attribute’xxx’
- [Solved] Pytorch Error: AttributeError: ‘Tensor‘ object has no attribute ‘backword‘
- [Solved] Pycharm error: attributeerror: ‘Htmlparser’ object has no attribute ‘unescape’