See here
graph_dict = {} for src_id, row in df.iterrows(): if row['below_obj_index'] != -1: graph_dict[src_id] = [row['below_obj_index']] if row['side_obj_index'] != -1: graph_dict[src_id] = [row['side_obj_index']]
See here