I have a dataframe with two columns as:
CHILD PARENT
1 2
2 3
3 4
10 11
11 12
I need to create a dictionary where I keep the top parent as key and all its descendents as set of values, like:
4: [1,2,3]
12: [10,11]
I have been able to extract 12 and 4 as top parents from this dataframe, by code from following link:
extract column value based on another column pandas dataframe
Now, I have no idea how to do this in python. In java I can do this by following a dfs. Any suggestions?