I have a hierarchical dataset which needs to be presented in a certain way. Items of the same hierarchy paths needs to be presented in successive order. Further parents should be listed above their children.
Appreciate any guidance to achieve the same..
Thank You
** sample dataset **
level Parent Child
0 z z
1 z o
1 z p
2 p t
2 p q
2 o r
** what i tried **
df = pd.read_clipboard(sep='\t')
df1=df.pivot(columns='level',values='Child')
df1.fillna('-',inplace=True)
df1
** my result **
level 0 1 2
0 z - -
1 - o -
2 - p -
3 - - t
4 - - q
5 - - r
** desired result **
level 0 1 2
0 z - -
1 - o -
2 - - r
3 - p -
4 - - t
5 - - q