text_html_output_1.png
import pandas as pd

FIGSIZE = (10, 6)
SAVE_PICKLE = True
FREE_MEMORY = True
OUTPUT_FILE = 'potential_energy_upd'
RANDOM_STATE = 123
N_SPLITS = 3
SHUFFLE = True
VERBOSE = False

DATA_PATH = '../input'
def csv_path(dataset='train', data_path=DATA_PATH):
    """
    """
    return '{}/{}.csv'.format(data_path, dataset)
def read_data(dataset='train', data_path=DATA_PATH):
    """
    """
    index_col = None
    index_type = ['train', 'test']
    if dataset in index_type:
        index_col = 'id'
    data_path = csv_path(dataset, data_path=data_path)
    return pd.read_csv(data_path, index_col=index_col)

train = read_data('train')
test = read_data('test')

molecule_train = pd.DataFrame({'molecule_name': train['molecule_name'].unique()})
molecule_test = pd.DataFrame({'molecule_name': test['molecule_name'].unique()})
structures = read_data('structures')
atom_list_df = structures.groupby('molecule_name')['atom'].apply(list)
atom_list_df = atom_list_df.to_frame()
if FREE_MEMORY:
    del train
    del test

molecule_train = pd.merge(molecule_train, atom_list_df, how='left', on='molecule_name')
molecule_test = pd.merge(molecule_test, atom_list_df, how='left', on='molecule_name')

potential_energy = read_data('potential_energy')
molecule_train = pd.merge(molecule_train, potential_energy)
if FREE_MEMORY:
    del potential_energy
    del structures

id_feature = 'molecule_name'
target_feature = (set(molecule_train) - set(molecule_test)).pop()
selected_features = list(molecule_test)
selected_features.remove(id_feature)
selected_features.remove('atom')

potential_energy_upd = pd.concat([molecule_train[[id_feature, target_feature]], molecule_test[[id_feature, target_feature]]], ignore_index=True)

potential_energy_upd = potential_energy_upd.sort_values(id_feature)
potential_energy_upd.reset_index(drop=True, inplace=True)

potential_energy_upd.head()