I have a dataframe with information regarding all employers from a given company. All employers should have an ID and the corresponding Manager ID.
Example:
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
(example: w reports to k and k reports to q and q reports to z)
I would like to get a new dataframe which contains information from all employers as follows:
child level1 level2 level x
a a - -
b a - -
d a b -
c a - -
f a c -
h a c f
g a c -
z z - -
q z - -
k z q -
w z q k
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.
'z'isn't a parent.