I have the following dataframe which contains Parent child relation:
data = pd.DataFrame({'Parent':['a','a','b','c','c','f','q','z','k'],
Child':['b','c','d','f','g','h','k','q','w']})
a
├── b
│ └── d
└── c
├── f
│ └── h
└── g
z
└── q
└── k
└── w
I would like to get a new dataframe which contains e.g. all children of parent a:
| child | level1 | level2 | level x |
|---|---|---|---|
| d | a | b | - |
| b | a | - | - |
| c | a | - | - |
| f | a | c | - |
| h | a | c | f |
| g | a | c | - |
I do not know how many levels there are upfront therefore I have used 'level x'.
I guess I somehow need a recursive pattern iterate over the dataframe.
'd'is a child of'b'? I see it in your diagram, but how does the data you have or that is being input showing that relationship? ah, nvm I see it now - the first parent is the parent of the first child, the second parent is the parent of the second child, etc. so d is the fourth child, and so is the child of the fourth parent