1

I've got a huge DataFrame. This just an example. But you can see that "b" element has "a", "d", "k" parents.

data = pd.DataFrame(columns=["Parent","Child"], data=[["a","b"],["a","d"],["d","v"],["d","b"],["c","f"],["b","n"],["s","c"],["k","b"],["n","k"]])

Read data from a pandas DataFrame and create a tree using anytree in python

In this solution tree is building, but parents overwriting.

How to build multiple parents tree? P.S Maybe my array is bad.

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76
wiwcomm
  • 11
  • 1

1 Answers1

1

Because anytree is a pure tree library, it supports only a single parent per node.

If you want to assign multiple parents to a node, you're looking at a directed graph. To work with such graphs in Python, try networkx

txp
  • 66
  • 2