I am trying to form a parent to child relationship combination using data available in my pandas dataframe.
Data Example:
| Parent | Child |
|---|---|
| A | B |
| A | C |
| B | D |
| B | C |
| C | D |
Expected chain results:
A|B
A|C
A|B|D
A|B|C
A|C|D
A|B|C|D
I tried something with networkx package to trace out the trees. I am partially successful. But it misses some of the hierarchies shown in the expected result.
Like, if the child has sub-nodes associated with it, it's not appearing as separate result.
For example, in the above data B is a child to A and has D & C are childs of B.
While applying my code, it shows A|B|D & A|B|C|D alone.
A|B is skipped as B has childs (C & D )
A|B|C is skipped as B has childs (C & D ) and subsequently C also has child (D)
A|C is skipped as C has child (D)
I used the code shown in below link
How to use recursion to record all routes in a parent child hierarchy?