{"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":"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-06-22T20:40:55.174243Z","iopub.execute_input":"2021-06-22T20:40:55.174779Z","iopub.status.idle":"2021-06-22T20:40:55.190841Z","shell.execute_reply.started":"2021-06-22T20:40:55.174678Z","shell.execute_reply":"2021-06-22T20:40:55.190129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\ntrain = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/train.csv')","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:40:55.194503Z","iopub.execute_input":"2021-06-22T20:40:55.195073Z","iopub.status.idle":"2021-06-22T20:41:55.242057Z","shell.execute_reply.started":"2021-06-22T20:40:55.195042Z","shell.execute_reply":"2021-06-22T20:41:55.241094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:41:58.924709Z","iopub.execute_input":"2021-06-22T20:41:58.925185Z","iopub.status.idle":"2021-06-22T20:41:58.94401Z","shell.execute_reply.started":"2021-06-22T20:41:58.925154Z","shell.execute_reply":"2021-06-22T20:41:58.943003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert training data date field to datetime type\ntrain['date'] = pd.to_datetime(train['date'], format=\"%Y%m%d\")","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:42:05.280344Z","iopub.execute_input":"2021-06-22T20:42:05.280679Z","iopub.status.idle":"2021-06-22T20:42:05.292748Z","shell.execute_reply.started":"2021-06-22T20:42:05.280649Z","shell.execute_reply":"2021-06-22T20:42:05.291918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:42:08.603077Z","iopub.execute_input":"2021-06-22T20:42:08.603393Z","iopub.status.idle":"2021-06-22T20:42:08.808848Z","shell.execute_reply.started":"2021-06-22T20:42:08.603366Z","shell.execute_reply":"2021-06-22T20:42:08.808229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['nextDayPlayerEngagement'][1215]  # It have the next day, the player Id, target 1, target 2, target 3, target 4","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:42:14.508062Z","iopub.execute_input":"2021-06-22T20:42:14.508525Z","iopub.status.idle":"2021-06-22T20:42:14.534446Z","shell.execute_reply.started":"2021-06-22T20:42:14.508497Z","shell.execute_reply":"2021-06-22T20:42:14.533421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['games'][1215]","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:42:44.95647Z","iopub.execute_input":"2021-06-22T20:42:44.956787Z","iopub.status.idle":"2021-06-22T20:42:44.962253Z","shell.execute_reply.started":"2021-06-22T20:42:44.95676Z","shell.execute_reply":"2021-06-22T20:42:44.961673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:51:43.209701Z","iopub.execute_input":"2021-06-22T20:51:43.210335Z","iopub.status.idle":"2021-06-22T20:51:43.430216Z","shell.execute_reply.started":"2021-06-22T20:51:43.210302Z","shell.execute_reply":"2021-06-22T20:51:43.429576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filas = train.shape","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:15:01.177114Z","iopub.execute_input":"2021-06-22T21:15:01.177584Z","iopub.status.idle":"2021-06-22T21:15:01.181132Z","shell.execute_reply.started":"2021-06-22T21:15:01.177553Z","shell.execute_reply":"2021-06-22T21:15:01.180411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filas_train = filas[0]","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:17:44.904714Z","iopub.execute_input":"2021-06-22T21:17:44.90526Z","iopub.status.idle":"2021-06-22T21:17:44.908642Z","shell.execute_reply.started":"2021-06-22T21:17:44.905216Z","shell.execute_reply":"2021-06-22T21:17:44.907989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions = pd.read_json(train['transactions'][1])\ntransactions","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:29:54.229619Z","iopub.execute_input":"2021-06-22T21:29:54.230104Z","iopub.status.idle":"2021-06-22T21:29:54.254251Z","shell.execute_reply.started":"2021-06-22T21:29:54.230073Z","shell.execute_reply":"2021-06-22T21:29:54.253331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import math","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:30:56.331313Z","iopub.execute_input":"2021-06-22T21:30:56.331651Z","iopub.status.idle":"2021-06-22T21:30:56.335654Z","shell.execute_reply.started":"2021-06-22T21:30:56.331621Z","shell.execute_reply":"2021-06-22T21:30:56.334667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['transactions'].isnull().count()","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:44:04.767486Z","iopub.execute_input":"2021-06-22T21:44:04.767808Z","iopub.status.idle":"2021-06-22T21:44:04.775784Z","shell.execute_reply.started":"2021-06-22T21:44:04.76778Z","shell.execute_reply":"2021-06-22T21:44:04.774625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_json = train['transactions']","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:46:43.632421Z","iopub.execute_input":"2021-06-22T21:46:43.632902Z","iopub.status.idle":"2021-06-22T21:46:43.636715Z","shell.execute_reply.started":"2021-06-22T21:46:43.632869Z","shell.execute_reply":"2021-06-22T21:46:43.635823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_json = transaction_json.dropna()\ntransaction_json.shape","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:50:04.154805Z","iopub.execute_input":"2021-06-22T21:50:04.155315Z","iopub.status.idle":"2021-06-22T21:50:04.16108Z","shell.execute_reply.started":"2021-06-22T21:50:04.155284Z","shell.execute_reply":"2021-06-22T21:50:04.160275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_json = transaction_json.reset_index()","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:54:14.685492Z","iopub.execute_input":"2021-06-22T21:54:14.68582Z","iopub.status.idle":"2021-06-22T21:54:14.691705Z","shell.execute_reply.started":"2021-06-22T21:54:14.685791Z","shell.execute_reply":"2021-06-22T21:54:14.690718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_json=transaction_json.drop(['index'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:55:19.568968Z","iopub.execute_input":"2021-06-22T21:55:19.569318Z","iopub.status.idle":"2021-06-22T21:55:19.576237Z","shell.execute_reply.started":"2021-06-22T21:55:19.569287Z","shell.execute_reply":"2021-06-22T21:55:19.575304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_json.head(7)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:55:21.210512Z","iopub.execute_input":"2021-06-22T21:55:21.210894Z","iopub.status.idle":"2021-06-22T21:55:21.218455Z","shell.execute_reply.started":"2021-06-22T21:55:21.210847Z","shell.execute_reply":"2021-06-22T21:55:21.217787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_json.isnull().count()","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:48:45.620743Z","iopub.execute_input":"2021-06-22T21:48:45.621084Z","iopub.status.idle":"2021-06-22T21:48:45.627897Z","shell.execute_reply.started":"2021-06-22T21:48:45.621055Z","shell.execute_reply":"2021-06-22T21:48:45.626806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['transactions'].head(7)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:48:45.717112Z","iopub.execute_input":"2021-06-22T21:48:45.717423Z","iopub.status.idle":"2021-06-22T21:48:45.723644Z","shell.execute_reply.started":"2021-06-22T21:48:45.717395Z","shell.execute_reply":"2021-06-22T21:48:45.722999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_json.head(7)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:51:12.936392Z","iopub.execute_input":"2021-06-22T21:51:12.936906Z","iopub.status.idle":"2021-06-22T21:51:12.943063Z","shell.execute_reply.started":"2021-06-22T21:51:12.936849Z","shell.execute_reply":"2021-06-22T21:51:12.942135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"b = pd.read_json(transaction_json[7])\nb","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:51:26.360568Z","iopub.execute_input":"2021-06-22T21:51:26.360912Z","iopub.status.idle":"2021-06-22T21:51:26.388791Z","shell.execute_reply.started":"2021-06-22T21:51:26.36088Z","shell.execute_reply":"2021-06-22T21:51:26.387734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filas = transaction_json.shape\nfilas = filas[0]\n","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:57:58.628321Z","iopub.execute_input":"2021-06-22T21:57:58.629048Z","iopub.status.idle":"2021-06-22T21:57:58.633532Z","shell.execute_reply.started":"2021-06-22T21:57:58.628996Z","shell.execute_reply":"2021-06-22T21:57:58.632849Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_total = pd.DataFrame()\nfor i in range(filas):\n    b = pd.read_json(transaction_json.transactions[i])\n    transactions_total = transactions_total.append(b)\ntransactions_total\n    ","metadata":{"execution":{"iopub.status.busy":"2021-06-22T22:06:53.172607Z","iopub.execute_input":"2021-06-22T22:06:53.172982Z","iopub.status.idle":"2021-06-22T22:07:25.827693Z","shell.execute_reply.started":"2021-06-22T22:06:53.172945Z","shell.execute_reply":"2021-06-22T22:07:25.826608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_total","metadata":{"execution":{"iopub.status.busy":"2021-06-22T22:05:56.61959Z","iopub.execute_input":"2021-06-22T22:05:56.619973Z","iopub.status.idle":"2021-06-22T22:05:56.626847Z","shell.execute_reply.started":"2021-06-22T22:05:56.619939Z","shell.execute_reply":"2021-06-22T22:05:56.625951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_total.append(b)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T22:06:08.196023Z","iopub.execute_input":"2021-06-22T22:06:08.196406Z","iopub.status.idle":"2021-06-22T22:06:08.235353Z","shell.execute_reply.started":"2021-06-22T22:06:08.19637Z","shell.execute_reply":"2021-06-22T22:06:08.234373Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"b.shape","metadata":{"execution":{"iopub.status.busy":"2021-06-22T22:05:25.447802Z","iopub.execute_input":"2021-06-22T22:05:25.448154Z","iopub.status.idle":"2021-06-22T22:05:25.453672Z","shell.execute_reply.started":"2021-06-22T22:05:25.448124Z","shell.execute_reply":"2021-06-22T22:05:25.452808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions_total","metadata":{"execution":{"iopub.status.busy":"2021-06-22T22:04:39.584171Z","iopub.execute_input":"2021-06-22T22:04:39.584497Z","iopub.status.idle":"2021-06-22T22:04:39.591504Z","shell.execute_reply.started":"2021-06-22T22:04:39.584469Z","shell.execute_reply":"2021-06-22T22:04:39.590429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions = pd.read_json(train['transactions'][1214])\ntransactions","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:12:38.073809Z","iopub.execute_input":"2021-06-22T21:12:38.074384Z","iopub.status.idle":"2021-06-22T21:12:38.126226Z","shell.execute_reply.started":"2021-06-22T21:12:38.074337Z","shell.execute_reply":"2021-06-22T21:12:38.125094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transactions.shape","metadata":{"execution":{"iopub.status.busy":"2021-06-22T21:13:01.473545Z","iopub.execute_input":"2021-06-22T21:13:01.473936Z","iopub.status.idle":"2021-06-22T21:13:01.479781Z","shell.execute_reply.started":"2021-06-22T21:13:01.473897Z","shell.execute_reply":"2021-06-22T21:13:01.478838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rosters = pd.read_json(train['rosters'][1214])\nrosters","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:52:06.375772Z","iopub.execute_input":"2021-06-22T20:52:06.376257Z","iopub.status.idle":"2021-06-22T20:52:06.399821Z","shell.execute_reply.started":"2021-06-22T20:52:06.376226Z","shell.execute_reply":"2021-06-22T20:52:06.398946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patients_df_2 = pd.read_json(train['games'][1214])\npatients_df_2","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:42:53.874758Z","iopub.execute_input":"2021-06-22T20:42:53.875104Z","iopub.status.idle":"2021-06-22T20:42:53.931728Z","shell.execute_reply.started":"2021-06-22T20:42:53.875062Z","shell.execute_reply":"2021-06-22T20:42:53.930845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"patients_df = pd.read_json(train['games'][1215])\npatients_df","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:45:15.050357Z","iopub.execute_input":"2021-06-22T20:45:15.051658Z","iopub.status.idle":"2021-06-22T20:45:15.114849Z","shell.execute_reply.started":"2021-06-22T20:45:15.051606Z","shell.execute_reply":"2021-06-22T20:45:15.114126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2021-06-16T17:13:49.965142Z","iopub.execute_input":"2021-06-16T17:13:49.965507Z","iopub.status.idle":"2021-06-16T17:13:50.154013Z","shell.execute_reply.started":"2021-06-16T17:13:49.965463Z","shell.execute_reply":"2021-06-16T17:13:50.153322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2021-06-16T17:38:37.599542Z","iopub.execute_input":"2021-06-16T17:38:37.599989Z","iopub.status.idle":"2021-06-16T17:38:37.827255Z","shell.execute_reply.started":"2021-06-16T17:38:37.599956Z","shell.execute_reply":"2021-06-16T17:38:37.826435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nextDayPlayerEngagement = pd.read_json(train['nextDayPlayerEngagement'][1212])\nnextDayPlayerEngagement","metadata":{"execution":{"iopub.status.busy":"2021-06-16T17:14:21.185396Z","iopub.execute_input":"2021-06-16T17:14:21.185782Z","iopub.status.idle":"2021-06-16T17:14:21.217706Z","shell.execute_reply.started":"2021-06-16T17:14:21.185748Z","shell.execute_reply":"2021-06-16T17:14:21.216789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rosters = pd.read_json(train['rosters'][1212])\nrosters","metadata":{"execution":{"iopub.status.busy":"2021-06-16T17:15:15.131486Z","iopub.execute_input":"2021-06-16T17:15:15.131853Z","iopub.status.idle":"2021-06-16T17:15:15.160686Z","shell.execute_reply.started":"2021-06-16T17:15:15.131819Z","shell.execute_reply":"2021-06-16T17:15:15.159782Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"playerBoxScores = pd.read_json(train['playerBoxScores'][1212])\nplayerBoxScores","metadata":{"execution":{"iopub.status.busy":"2021-06-16T17:16:31.524691Z","iopub.execute_input":"2021-06-16T17:16:31.525026Z","iopub.status.idle":"2021-06-16T17:16:31.59689Z","shell.execute_reply.started":"2021-06-16T17:16:31.524997Z","shell.execute_reply":"2021-06-16T17:16:31.596005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"teamBoxScores = pd.read_json(train['teamBoxScores'][1212])\nteamBoxScores","metadata":{"execution":{"iopub.status.busy":"2021-06-16T17:17:48.55075Z","iopub.execute_input":"2021-06-16T17:17:48.551091Z","iopub.status.idle":"2021-06-16T17:17:48.596972Z","shell.execute_reply.started":"2021-06-16T17:17:48.551061Z","shell.execute_reply":"2021-06-16T17:17:48.596106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.dtypes","metadata":{"execution":{"iopub.status.busy":"2021-06-16T17:28:17.05652Z","iopub.execute_input":"2021-06-16T17:28:17.057022Z","iopub.status.idle":"2021-06-16T17:28:17.064541Z","shell.execute_reply.started":"2021-06-16T17:28:17.056987Z","shell.execute_reply":"2021-06-16T17:28:17.063882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/example_test.csv')","metadata":{"execution":{"iopub.status.busy":"2021-06-16T17:05:43.349096Z","iopub.execute_input":"2021-06-16T17:05:43.34942Z","iopub.status.idle":"2021-06-16T17:05:43.881269Z","shell.execute_reply.started":"2021-06-16T17:05:43.349385Z","shell.execute_reply":"2021-06-16T17:05:43.880392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example","metadata":{"execution":{"iopub.status.busy":"2021-06-15T17:10:00.811302Z","iopub.execute_input":"2021-06-15T17:10:00.811681Z","iopub.status.idle":"2021-06-15T17:10:01.016687Z","shell.execute_reply.started":"2021-06-15T17:10:00.811648Z","shell.execute_reply":"2021-06-15T17:10:01.015578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"example_submit = pd.read_csv('../input/mlb-player-digital-engagement-forecasting/example_sample_submission.csv')\nexample_submit","metadata":{"execution":{"iopub.status.busy":"2021-06-22T20:48:16.990506Z","iopub.execute_input":"2021-06-22T20:48:16.991242Z","iopub.status.idle":"2021-06-22T20:48:17.025774Z","shell.execute_reply.started":"2021-06-22T20:48:16.991191Z","shell.execute_reply":"2021-06-22T20:48:17.025029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}