{"cells":[{"metadata":{},"cell_type":"markdown","source":"Here you are."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Load data"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","collapsed":true,"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":false},"cell_type":"code","source":"# load data\n# train_df = pd.read_csv('../input/train.csv')\npotential_energy_df = pd.read_csv('../input/potential_energy.csv')\nmulliken_charges_df = pd.read_csv('../input/mulliken_charges.csv')\nscalar_coupling_contributions_df = pd.read_csv('../input/scalar_coupling_contributions.csv')\nmagnetic_shielding_tensors_df = pd.read_csv('../input/magnetic_shielding_tensors.csv')\ndipole_moments_df = pd.read_csv('../input/dipole_moments.csv')\n# structure_df = pd.read_csv('../input/structures.csv')\n# test_df = pd.read_csv('../input/test.csv')\n\nprint(\"All the additional data were loaded.\")","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Merge files"},{"metadata":{"trusted":true},"cell_type":"code","source":"# combine \"dipole_moments_df\" and \"potential_energy_df\" (The both have 85003 rows)\nDM_PE_df = pd.merge(dipole_moments_df, potential_energy_df, on='molecule_name')\n\n# combine \"magnetic_shielding_tensors_df\" and \"mulliken_charges_df\" (The both have 1533537 rows)\nMST_MC_df = pd.merge(magnetic_shielding_tensors_df, mulliken_charges_df, on=['molecule_name', 'atom_index'])\n\n# combine these two\nMST_MC_DM_PE_df = pd.merge(MST_MC_df, DM_PE_df, on='molecule_name', how='left')\n\n# combine it with \"scaler_coupling_contributions_df\" \ncombined_df = pd.merge(scalar_coupling_contributions_df, MST_MC_DM_PE_df, \n                           left_on=['molecule_name','atom_index_0'], right_on=['molecule_name','atom_index'], how='left')\ncombined_df1 = pd.merge(scalar_coupling_contributions_df, MST_MC_DM_PE_df, \n                           left_on=['molecule_name','atom_index_1'], right_on=['molecule_name','atom_index'], how='left')\n\n# average values between atom_index_0 and atom_index_1\nfor c in list(MST_MC_DM_PE_df.columns.values)[2:]:\n    combined_df[c] = (combined_df[c] + combined_df1[c]) / 2\n\ncombined_df = combined_df.drop(['atom_index'], axis=1)\nprint('Combined DF has {} rows and {} columns'.format(combined_df.shape[0], combined_df.shape[1]))\n\n# save as csv\ncombined_df.to_csv('combined_additional_data.csv',index=False)\n\n# head of the file\ncombined_df.head(12)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}