{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import pandas as pd\nimport numpy as np","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def first_leak_pp(df):\n    df.fillna(0, inplace=True)\n    df.loc[df.meter_reading < 0, 'meter_reading'] = 0 # remove large negative values\n    df = df[df.building_id!=245]\n    df['meter'] = df['meter'].astype(int)\n    return df\n\nclass LeakAgregator(object):\n    def __init__(self, list_of_leak_dicts):\n        self.list_of_leak_dicts = list_of_leak_dicts\n        self.leak_dfs = [el['preprocessing'](el['read'](el['path'])) for el in self.list_of_leak_dicts]\n        self.overall_df = pd.concat(self.leak_dfs, axis=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"leak_dict = [\n    {\n        'path':'../input/ashrae-leak-data-station/leak.feather',\n        'read':pd.read_feather,\n        'preprocessing':first_leak_pp\n    }\n]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ob = LeakAgregator(leak_dict)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/ashrae-energy-prediction/test.csv', parse_dates=['timestamp'])\ntest = test.merge(ob.overall_df, on=['building_id','meter','timestamp'], how='left')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ob.overall_df.to_csv('leak_df.csv',index=False)\ntest[['row_id','meter_reading']].to_csv('leaked_test_target.csv',index=False)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}