anytree
is a Lightweight Python Tree Data Structure.
Questions tagged [anytree]
67 questions
1
vote
1 answer
How to build a tree in python?
I've been futzing around with the anytree and treelib libraries for the last few days, but I can't figure out how to actually build the tree. I'm sure there's something relatively simple I'm missing. Basically, I need to build an org chart. My data…

RNGeezy
- 55
- 8
1
vote
1 answer
Best way to simplify a nested python list into a structured tree (while retaining order)
Let's say that I have a Python 3.6 list that looks like this:
l1 = [
[a,b,c],
[b,c],
[c],
[d, e],
[e]
...
]
I need to convert this to a tree-like structure using anytree, so that it looks like this:
>>>…

Ali Abbas
- 136
- 1
- 8
1
vote
1 answer
constructing a tree view from a nested list with duplicate subtrees (using anytree/treelib)
I have a nested list like the following:
lst = [['a', 'b', 'e'], # this e is the branch of b
['a', 'f', 'e'], # this e is the branch of f,
['a', 'h', 'i i i']] # string with spaces
and I wanna to construct a tree…

steven
- 2,130
- 19
- 38
1
vote
0 answers
Tree constrction from csv with labeled edge
I have a csv file, and want to construct a tree by reading the file contents
id | screen_name | reply_status_id | tweet | stance
1 | a | null | dahgfsjhg | +
2 | b | 1 …

Student
- 41
- 2
- 10
1
vote
1 answer
Tree graph with python AnyTree package
I need to generate a tree from a dictionary with python AnyTree package.so I have a dictionary like below structure.
data = {'name': 'xyz',
'children': [{'name': 'node1',
'children': [{'name': 'node2'}]}]}
This…

Akalanka
- 65
- 1
- 12
1
vote
0 answers
Creating an inheritance tree from pandas dataframe
I have a dataframe like this:
Genome Evolved_from
3435XY 233Z
5662YY 1099N
1099N 234YY
234YY 22QQ
43543Z 232XX
4566Y 1099N
213TY 15Q
234YY 12Q
7968ZT 2132X
77792 213TY
2455Z …

edyvedy13
- 2,156
- 4
- 17
- 39
1
vote
1 answer
Access specific children on anytree
I have started using anytree but currently facing some challenge iterating on my tree.
Test tree:
top = Node("top", keywords="topleveltree")
hello = Node("hello", keywords="hello", parent=top)
hello1 = Node("hello X", keywords="hello X", answer="Say…

PERPO
- 3,812
- 1
- 13
- 20
1
vote
0 answers
Python Tree with unknown Height
Assume I have 2 columns:
OP_CODE Additional Work
a b
a c
a
b d
b e
c
d f
d g
d …

Shubzumt
- 143
- 1
- 12
1
vote
2 answers
Name not defined when using Anytree class
I am working with Python's anytree package, and I am trying to iterate over the tree:
from anytree import Node, RenderTree, AsciiStyle
f = Node("f")
b = Node("b", parent=f)
a = Node("a", parent=b)
print(RenderTree(f,…

ChildinTime
- 151
- 1
- 1
- 10
0
votes
0 answers
Does AnyTree support multiple nodes with same name in different hierarchies?
I am trying to create a tree with a node that can appear in more than 1 hierarchies.
Example:
A --> B ; A --> C ; A --> D --> C
Alternatively, I can think of them as separate nodes but 'C' under 'A' and 'C' under 'D' will need to have the same…

Srijit Misra
- 1
- 1
0
votes
1 answer
Python script to extract data from an excel and put it in trees
I have a python script that extracts data from an excel, more precisely, data from three columns: Finished Good, Parent Part Code and Material Code. The three columns look like this:
Material Code Parent Part Code Finished Good
M1 …

David
- 15
- 4
0
votes
1 answer
Simple list of branch for a Node Python AnyTree
Given a simple tree in AnyTree, when I look at a node it tells me its path to the root, but I cannot find anything that will simply give me that path as a list of the node names, or as a string which I can simply turn into a list of the…

RossGK
- 515
- 2
- 7
- 19
0
votes
1 answer
How to build a Python anytree tree based on another tree?
If I have this tree:
# mytree.py
import anytree as at
import anytree.importer
data = {
"a": "root",
"children": [
{
"a": "sub0",
"b": 3,
"children": [{"a": "sub0A", "b": 9}, {"a": "sub0B", "b":…

Daniel Diniz
- 175
- 8
0
votes
1 answer
Renaming Anytree Parent and Child Name
I have a dataset as follows
Unique Name
Parent
Child
US_SQ
A
A1
UC_LC
A
A2
UK_SJ
A2
A21
UI_QQ
B
B1
Now I want to set the output as follows:
US_SQ
├── A1
└── UC_LC
└── UK_SJ
UI_QQ
└── B1
In other words, I want to use the…

Abdullah Al Mamun
- 65
- 7
0
votes
0 answers
Right align vertical dot graph with DotExporter
I have a vertical dot graph with multiple layers of nodes and edges. The last level has different lengths of labels. I want to align these to the right of the img.
from anytree.exporter import DotExporter
from anytree import Node
example =…

Danielle
- 1