I have two rows for each child where I am trying to group by on Child Name and flatten Parent's name in Same row.
CHILD_FIRST_NAME CHILD_LAST_NAME PARENT_FIRST_NAME PARENT_LAST_NAME PARENT_GENDER
Sarah Marshal David Marshal M
Sarah Marshal Caren Marshal F
Kiran Mishra Raj Mishra M
Kiran Mishra Geetha Mishra F`
Output should be
CHILD_FIRST_NAME CHILD_LAST_NAME FATHER_FIRST_NAME FATHER_LAST_NAME MOTHER_FIRST_NAME MOTHER_LAST_NAME
Sarah Marshal David Marshal Caren Marshal
Kiran Mishra Raj Mishra Geetha Mishra
I tried this code, which helps me to flatten 'PARENT_FIRST_NAME' only but couldn't figure out an option to include 'PARENT_LAST_NAME'
df.groupby(['CHILD_FIRST_NAME','CHILD_LAST_NAME','PARENT_GENDER'])['PARENT_FIRST_NAME'].max().unstack().rename(columns={'M': 'FATHER_FIRST_NAME', 'F': 'MOTHER_FIRST_NAME'})