I have a pandas dataframe as such:
parent child parent_level child_level
A B 0 1
B C 1 2
B D 1 2
X Y 0 2
X D 0 2
Y Z 2 3
This represents a tree that looks like this
A X
/ / \
B / \
/\ / \
C D Y
|
Z
I want to produce something that looks like this:
root children
A [B,C,D]
X [D,Y,Z]
or
root child
A B
A C
A D
X D
X Y
X Z
What is the fastest way to do so without looping. I have a really large dataframe.