First Question on StackOverflow. Haven't been able to find other instances of this problem which leads me to believe I'm doing something incorrectly.
I'm attempting to create a tree from Bill of Material (BOM) data. To start with I am only trying to get basic parent>child nodes set up.
from anytree import Node, RenderTree, find_by_attr, NodeMixin
import pandas as pd
# Create Dataframe from csv file
df1 = pd.read_csv(r'filepath') # filepath only used for example
nodes = {} # Store created nodes
root = Node('root') # Setup root node
# Iterate over df and create parent/child nodes
for index, row in df1.iterrows():
pitem = row['EBPART'].strip() # get parent item number
citem = row['EBCOMP'].strip() # get child item number
nodes[pitem] = Node(pitem,parent=root) # create child node
nodes[citem] = Node(citem,parent=pitem) # create parent node
Basically during iteration I'm attempting to create the parent node (which does not throw an error) and then create a child node using the previously created node as it's parent. But, I continually get this error:
anytree.node.exceptions.TreeError: Parent node 'Product1' is not of type 'NodeMixin'.
Here is the result of rendertree(root):
print(RenderTree(root))
Node('/root')
└── Node('/root/322601101')
Here is a simplified version of the csv I'm reading:
Any help is greatly appreciated!