This is a subset of the main dataframe. The whole columns are lister in the dictionary below
age_groups_type procedureschoice=aortic_valve_repair procedureschoice=arterial_switch
0 Pediatrics False True
1 Pediatrics False True
2 Pediatrics False True
3 Adults True False
4 Adults True False
5 Pediatrics False True
6 Adults True False
7 Pediatrics False True
8 Adults True False
9 Pediatrics False True
This dictionary contains the category of each operation whether being 'Aortic', 'Mitral'. etc. and their corresponding age_group_type
whether being 'Adults' or 'pediatrics' (children)
{'Adults': {'Aortic': {'procedureschoice=aortic_valve_repair',
'procedureschoice=arch_replacement',
'procedureschoice=ascending_aortic_replacement',
'procedureschoice=avrmechanical',
'procedureschoice=avrstented_bioprosthesis',
'procedureschoice=bentall',
'procedureschoice=freestyle',
'procedureschoice=homograft_aortic_root_replacement',
'procedureschoice=ross',
'procedureschoice=valve-sparing_aortic_root_replacement'},
'Mitral': {'procedureschoice=mitral_valve_repair',
'procedureschoice=mvrmechanical',
'procedureschoice=mvrstented_bioprosthesis'},
'Tricuspid': {'procedureschoice=tricuspid_valve_repair',
'procedureschoice=tvrmechanical',
'procedureschoice=tvrstented_bioprosthesis'},
'CABG': {'procedureschoice=cabg'},
'Myectomy': {'procedureschoice=myectomy'},
'GUCH': {'procedureschoice=alcapa_repair',
'procedureschoice=arterial_switch',
'procedureschoice=asd_closure',
'procedureschoice=atrial_septectomy',
'procedureschoice=atrial_switchmustard',
'procedureschoice=av_canal_repairpartial',
'procedureschoice=av_canal_repairtransitional',
'procedureschoice=central_shunt',
'procedureschoice=coarctectomy_with_extended_end-to-end_anastomosis',
'procedureschoice=cor-triatriatum_repair',
'procedureschoice=coronary_av_fistula_repair',
'procedureschoice=extra-anatomical_bypass_of_coa',
'procedureschoice=fallot_repair',
'procedureschoice=fontan',
'procedureschoice=glenn',
'procedureschoice=lpa_reconstruction',
'procedureschoice=mbt_shunt',
'procedureschoice=mpa_reconstruction',
'procedureschoice=pa_banding',
'procedureschoice=papvc_repair',
'procedureschoice=pda_closure',
'procedureschoice=pulmonary_trans-annular_patch',
'procedureschoice=pulmonary_valve_replacementfreestyle',
'procedureschoice=pulmonary_valve_replacementhomograft',
'procedureschoice=pulmonary_valve_replacementstented_bioprosthesis',
'procedureschoice=pulmonary_valvotomy',
'procedureschoice=rastelli',
'procedureschoice=relief_of_rvoto',
'procedureschoice=resection_of_subaortic_membrane',
'procedureschoice=rpa_reconstruction',
'procedureschoice=rupture_sinus_of_valsalva_repair',
'procedureschoice=rvot_patch',
'procedureschoice=supravalvular_as_repair',
'procedureschoice=vascular_ring_repair',
'procedureschoice=vsd_closure'}},
'Pediatrics': {'VSD': {'procedureschoice=vsd_closure'},
'TGA': {'procedureschoice=arterial_switch',
'procedureschoice=atrial_switchmustard',
'procedureschoice=rastelli'},
'Arch': {'procedureschoice=arch_repair',
'procedureschoice=coarctectomy_with_extended_end-to-end_anastomosis',
'procedureschoice=extra-anatomical_bypass_of_coa'},
'Canal': {'procedureschoice=av_canal_repaircomplete',
'procedureschoice=av_canal_repairpartial',
'procedureschoice=av_canal_repairtransitional'},
'Valvular': {'procedureschoice=aortic_valve_repair',
'procedureschoice=avrmechanical',
'procedureschoice=avrstented_bioprosthesis',
'procedureschoice=bentall',
'procedureschoice=freestyle',
'procedureschoice=homograft_aortic_root_replacement',
'procedureschoice=maze_procedure',
'procedureschoice=mitral_valve_repair',
'procedureschoice=mvrmechanical',
'procedureschoice=mvrstented_bioprosthesis',
'procedureschoice=ross',
'procedureschoice=tricuspid_valve_repair',
'procedureschoice=tvrmechanical',
'procedureschoice=tvrstented_bioprosthesis',
'procedureschoice=valve-sparing_aortic_root_replacement'},
'RVOT_PA': {'procedureschoice=fallot_repair',
'procedureschoice=lpa_reconstruction',
'procedureschoice=mpa_reconstruction',
'procedureschoice=pulmonary_trans-annular_patch',
'procedureschoice=pulmonary_valve_replacementfreestyle',
'procedureschoice=pulmonary_valve_replacementhomograft',
'procedureschoice=pulmonary_valve_replacementstented_bioprosthesis',
'procedureschoice=pulmonary_valvotomy',
'procedureschoice=relief_of_rvoto',
'procedureschoice=rpa_reconstruction',
'procedureschoice=rvot_patch'},
'Palliative': {'procedureschoice=atrial_septectomy',
'procedureschoice=central_shunt',
'procedureschoice=dks',
'procedureschoice=first_stage_switchpab,_bts',
'procedureschoice=fontan',
'procedureschoice=glenn',
'procedureschoice=mbt_shunt',
'procedureschoice=pa_banding'}}}
what I need is to create a new column procedure_group
that filled with the dictionary keys ['Aortic', 'Mitral', 'Tricuspid', 'CABG', 'Myectomy', 'GUCH']
for adult patients and ['VSD', 'TGA', 'Arch', 'Canal', 'Valvular', 'RVOT_PA', 'Palliative']
for pediatric patients.
I tried this
def code_map(row):
for key in code.keys():
for i in code[key].keys():
for k in list(code[key][i]):
if row[row['age_groups_type'] == 'Adults' & row[k] == True]:
return i
elif row[row['age_groups_type'] == 'Pediatrics' & row[k] == True]:
return i
df['procedure_group'] = df.apply(code_map, axis=1)
and this
def code_map(df):
for col in df:
for i in range(len(adult_list)):
if code["Adults"][i][col] == True:
return code["Adults"][i]
for i in range(len(pediatrics_list)):
if code["Pediatrics"][i][col] == True:
return code["Pediatrics"][i]
df['procedure_group'] = df.apply(code_map(df), axis=1)
and other solutions, but all trials failed.
The final output will be like this
age_groups_type procedureschoice=aortic_valve_repair procedureschoice=arterial_switch procedure_group
0 Pediatrics False True TGA
1 Pediatrics True False Aortic
2 Pediatrics False True TGA
3 Adults True False Aortic
4 Adults True False Aortic
5 Pediatrics False True TGA
6 Adults True False Aortic
7 Pediatrics False True TGA
8 Adults True False Aortic
9 Pediatrics False True TGA
The logic I'm thinking of is if, in each row, the procedure is True
and the patient is Adults, return the dictionary values corresponding this row.
How can I do this?