{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"This kernel is designed to create partitioned datasets. You can modify it according to your needs and use it for various purposes. (Please check the data set rules of the competition)","metadata":{}},{"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\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-14T23:38:13.178750Z","iopub.execute_input":"2021-12-14T23:38:13.179270Z","iopub.status.idle":"2021-12-14T23:38:13.222333Z","shell.execute_reply.started":"2021-12-14T23:38:13.179107Z","shell.execute_reply":"2021-12-14T23:38:13.221526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1. Load datasets","metadata":{}},{"cell_type":"code","source":"all_df = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/train.csv')\nall_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:38:13.223683Z","iopub.execute_input":"2021-12-14T23:38:13.224544Z","iopub.status.idle":"2021-12-14T23:39:20.077161Z","shell.execute_reply.started":"2021-12-14T23:38:13.224501Z","shell.execute_reply":"2021-12-14T23:39:20.076122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"asset_details = pd.read_csv('/kaggle/input/g-research-crypto-forecasting/asset_details.csv')\nasset_details.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:39:20.079233Z","iopub.execute_input":"2021-12-14T23:39:20.079571Z","iopub.status.idle":"2021-12-14T23:39:20.100230Z","shell.execute_reply.started":"2021-12-14T23:39:20.079528Z","shell.execute_reply":"2021-12-14T23:39:20.099255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 2. Merge datasets","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:17:40.806839Z","iopub.execute_input":"2021-12-14T23:17:40.80751Z","iopub.status.idle":"2021-12-14T23:17:40.812035Z","shell.execute_reply.started":"2021-12-14T23:17:40.807463Z","shell.execute_reply":"2021-12-14T23:17:40.811158Z"}}},{"cell_type":"code","source":"all_df = all_df.join(asset_details.set_index('Asset_ID'), on='Asset_ID')\nall_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:39:20.102637Z","iopub.execute_input":"2021-12-14T23:39:20.102882Z","iopub.status.idle":"2021-12-14T23:39:23.382350Z","shell.execute_reply.started":"2021-12-14T23:39:20.102852Z","shell.execute_reply":"2021-12-14T23:39:23.381244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Check if the length of the dataset is the same before and after merging","metadata":{}},{"cell_type":"code","source":"len(all_df['Asset_ID'].unique()) == len(all_df['Asset_Name'].unique())","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:39:23.383802Z","iopub.execute_input":"2021-12-14T23:39:23.384072Z","iopub.status.idle":"2021-12-14T23:39:25.489757Z","shell.execute_reply.started":"2021-12-14T23:39:23.384038Z","shell.execute_reply":"2021-12-14T23:39:25.488716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 3. Split dataset(Partitioning)","metadata":{}},{"cell_type":"code","source":"asset_details","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:39:25.491215Z","iopub.execute_input":"2021-12-14T23:39:25.491471Z","iopub.status.idle":"2021-12-14T23:39:25.503724Z","shell.execute_reply.started":"2021-12-14T23:39:25.491439Z","shell.execute_reply":"2021-12-14T23:39:25.503028Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Split the data according to asset_id, Remove and re-create existing indexes so that indexes are organized in order along with data partitioning. In fact, we will save the data file without index, but for those who will continue to analyze in this kernel, the process is duplicated.","metadata":{}},{"cell_type":"code","source":"bitcoin_cash_df = all_df.loc[all_df['Asset_ID']==2,:].reset_index(drop=True)\nbinance_coin_df = all_df.loc[all_df['Asset_ID']==0,:].reset_index(drop=True)\nbitcoin_df = all_df.loc[all_df['Asset_ID']==1,:].reset_index(drop=True)\neos_df = all_df.loc[all_df['Asset_ID']==5,:].reset_index(drop=True)\nethereum_classic_df = all_df.loc[all_df['Asset_ID']==7,:].reset_index(drop=True)\nethereum_df = all_df.loc[all_df['Asset_ID']==6,:].reset_index(drop=True)\nlitecoin_df = all_df.loc[all_df['Asset_ID']==9,:].reset_index(drop=True)\nmonero_df = all_df.loc[all_df['Asset_ID']==11,:].reset_index(drop=True)\ntron_df = all_df.loc[all_df['Asset_ID']==13,:].reset_index(drop=True)\nstellar_df = all_df.loc[all_df['Asset_ID']==12,:].reset_index(drop=True)\ncardano_df = all_df.loc[all_df['Asset_ID']==3,:].reset_index(drop=True)\niota_df = all_df.loc[all_df['Asset_ID']==8,:].reset_index(drop=True)\nmaker_df = all_df.loc[all_df['Asset_ID']==10,:].reset_index(drop=True)\ndogecoin_df = all_df.loc[all_df['Asset_ID']==4,:].reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:39:25.504824Z","iopub.execute_input":"2021-12-14T23:39:25.505542Z","iopub.status.idle":"2021-12-14T23:39:33.476195Z","shell.execute_reply.started":"2021-12-14T23:39:25.505505Z","shell.execute_reply":"2021-12-14T23:39:33.475108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 4. Check the partitioned dataset","metadata":{}},{"cell_type":"markdown","source":"Check the length of the entire dataset and the partitioned dataset to make sure no assets are missing in the process","metadata":{}},{"cell_type":"code","source":"len(bitcoin_cash_df) + len(binance_coin_df) + len(bitcoin_df) + len(eos_df) + len(ethereum_classic_df) + len(ethereum_df) + len(litecoin_df) + \\\nlen(monero_df) + len(tron_df) + len(stellar_df) + len(cardano_df) + len(iota_df) + len(maker_df) + len(dogecoin_df)","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:39:33.477546Z","iopub.execute_input":"2021-12-14T23:39:33.477919Z","iopub.status.idle":"2021-12-14T23:39:33.487024Z","shell.execute_reply.started":"2021-12-14T23:39:33.477871Z","shell.execute_reply":"2021-12-14T23:39:33.485972Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(all_df)","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:39:33.488869Z","iopub.execute_input":"2021-12-14T23:39:33.489346Z","iopub.status.idle":"2021-12-14T23:39:33.502103Z","shell.execute_reply.started":"2021-12-14T23:39:33.489296Z","shell.execute_reply":"2021-12-14T23:39:33.500856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 5. Save datasets","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:26:07.302842Z","iopub.execute_input":"2021-12-14T23:26:07.303229Z","iopub.status.idle":"2021-12-14T23:26:07.308386Z","shell.execute_reply.started":"2021-12-14T23:26:07.303189Z","shell.execute_reply":"2021-12-14T23:26:07.307532Z"}}},{"cell_type":"markdown","source":"check the path to save data files","metadata":{}},{"cell_type":"code","source":"!pwd","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:39:33.504761Z","iopub.execute_input":"2021-12-14T23:39:33.505130Z","iopub.status.idle":"2021-12-14T23:39:34.309568Z","shell.execute_reply.started":"2021-12-14T23:39:33.505094Z","shell.execute_reply":"2021-12-14T23:39:34.308439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Save data to that path","metadata":{}},{"cell_type":"code","source":"bitcoin_cash_df.to_csv(\"./bitcoin_cash.csv\", index=False)\nbinance_coin_df.to_csv(\"./binance_coin.csv\", index=False)\nbitcoin_df.to_csv(\"./bitcoin.csv\", index=False)\neos_df.to_csv(\"./eos.csv\", index=False)\nethereum_classic_df.to_csv(\"./ethereum_classic.csv\", index=False)\nethereum_df.to_csv(\"./ethereum.csv\", index=False)\nlitecoin_df.to_csv(\"./litecoin.csv\", index=False)\nmonero_df.to_csv(\"./monero.csv\", index=False)\ntron_df.to_csv(\"./tron.csv\", index=False)\nstellar_df.to_csv(\"./stellar.csv\", index=False)\ncardano_df.to_csv(\"./cardano.csv\", index=False)\niota_df.to_csv(\"./iota.csv\", index=False)\nmaker_df.to_csv(\"./maker.csv\", index=False)\ndogecoin_df.to_csv(\"./dogecoin.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2021-12-14T23:39:34.311347Z","iopub.execute_input":"2021-12-14T23:39:34.311626Z","iopub.status.idle":"2021-12-14T23:46:18.151271Z","shell.execute_reply.started":"2021-12-14T23:39:34.311594Z","shell.execute_reply":"2021-12-14T23:46:18.149813Z"},"trusted":true},"execution_count":null,"outputs":[]}]}