text_plain_output_1.png
import pandas as pd # data       , CSV file I/O (e.g. pd.read_csv)

df_train = pd.read_csv('../input/train.csv')

structures = pd.read_csv('../input/structures.csv')

molecule = 'dsgdb9nsd_000001'

a = df_train.loc[df_train['molecule_name'] == f'{molecule}']
b = structures[structures.molecule_name == f'{molecule}']

def convert_index_to_atom(a, b, atom_index):
    c = a.merge(b, how='left', left_on=['molecule_name', f'atom_index_{atom_index}'], right_on=['molecule_name', 'atom_index'])
    c.drop('atom_index', axis=1, inplace=True)
    c.rename(columns={'atom': f'atom_{atom_index}', 'x': f'x_{atom_index}', 'y': f'y_{atom_index}', 'z': f'z_{atom_index}'}, inplace=True)
    c.drop(f'atom_index_{atom_index}', axis=1, inplace=True)
    return c

c = convert_index_to_atom(df_train, structures, 0)
c = convert_index_to_atom(c, structures, 1)

types = list(c.groupby('type').groups)
types