# to sort these into tables:
sids =[]
marr_val =[[]for i in df['marriage_related'][0][0].keys()]# for other variables# work_val = [[] for i in df['work_related'][0][0].keys()]# ...for i, el inenumerate(df['survey_id']):
sids.extend([el for i in marriage_related[i]])for j, lst inenumerate(marr_val):
lst.extend(np.array(marriage_related[i])[:,j])# casting to np array so that indexing can be easier# the others can be listed below (work_val, ..., age_val)# ^ which means this loop will be 5x the amount of code as above :)
marriage_related_df ={'survey_id': sids}for i, el inenumerate(df['marriage_related'][0][0].keys()):
marriage_related_df[el]= marr_val[i]
pd.DataFrame(marriage_related_df)