Python anytree - not of type 'NodeMixin' Error

110 Views Asked by At

I am trying to build a Hierarchy from the below csv data:

Child,Parent,IsActive
11074165,11018432,NO
11094122,11033371,NO
11020499,11018277,NO
11018432,11020499,NO

Below is the code snippet

nodes = {}
with open("SampleHierarchy.csv", "r") as f:
    csv_reader = csv.DictReader(f)
    for row in csv_reader:
        #print(row['Code'], row['Parent'],row['IsActive'])
        childItem=row['Code']
        parentItem=row['Parent']
        nodes[childItem] = Node(childItem, parent=parentItem)

But getting the Error:

*Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
    execfile(filename, namespace)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)
  File "CounterpartyHierarchyTree.py", line 37, in <module>
    Node(childItem, parent=parentItem)
  File "C:\ProgramData\Anaconda3\lib\site-packages\anytree\node\node.py", line 77, in __init__
    self.parent = parent
  File "C:\ProgramData\Anaconda3\lib\site-packages\anytree\node\nodemixin.py", line 127, in parent
    raise TreeError(msg)
anytree.node.exceptions.TreeError: Parent node '11018432' is not of type 'NodeMixin'.*

Can you please advise how to fix the same?

Thanks.

0

There are 0 best solutions below