How to convert Parent/Child datatable to list or hierarchy datatable structure

Hi, Guys!
Is there a way to convert P/C datatable to list or hierarchy datatable structure? Thanks!

Hi @donfeng91

Could you provide further explanation ?

Hi @donfeng91 ,
You can convert to Json format of Parent and child information hierarchy.

or

you can have multiple table with linking of parent id in the child table.

Regards,
Arivu

Of course. As below picture, I have two databases stores the info of state-city-district in P/C data structure. In order to verify their consistency, firstly convert both of the two to hierarchy structure. Then make a comparison.

I have tried the first way with python, using df.to_json function. No matter the “orient” argument placed, the result is not expected.
Actually, I did it with python networkx package. Quite complicated.

@donfeng91

are you looking for something like this

data = {"parent": [0, 0, 1, 1, 2, 4], "child": [1, 2, 3, 4, 5, 5]}

Parent	Node	Level
0	1	1
0	2	1
1	3	2
1	4	2
2	5	2
4	5	3


@muktadir no, it should be like this: