{"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":"# Explanation of train.csv each variable","metadata":{}},{"cell_type":"markdown","source":"The purpose is to understand what the characteristics are.<br>\nThis NoteBook is written Japanese.([日本語バーションはこちら](https://www.kaggle.com/fumiyakomatsu/train-csv)) <br>\nAnd I translate through Google translate.<br>\nSo please pardon translate miss.","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-06-20T05:38:10.474035Z","iopub.execute_input":"2021-06-20T05:38:10.474528Z","iopub.status.idle":"2021-06-20T05:38:10.487569Z","shell.execute_reply.started":"2021-06-20T05:38:10.474482Z","shell.execute_reply":"2021-06-20T05:38:10.486535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pathlib import Path\nimport gc\nimport sys\nimport ipywidgets as widgets\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:38:10.489285Z","iopub.execute_input":"2021-06-20T05:38:10.489732Z","iopub.status.idle":"2021-06-20T05:38:11.593048Z","shell.execute_reply.started":"2021-06-20T05:38:10.489689Z","shell.execute_reply":"2021-06-20T05:38:11.592000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load train.csv","metadata":{}},{"cell_type":"code","source":"data_dir = Path('../input/mlb-player-digital-engagement-forecasting/')\ntraining = pd.read_csv(data_dir / 'train.csv')\n\n# Convert training data date field to datetime type\ntraining['date'] = pd.to_datetime(training['date'], format=\"%Y%m%d\")\n\ndisplay(training.info())","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:38:11.594982Z","iopub.execute_input":"2021-06-20T05:38:11.595302Z","iopub.status.idle":"2021-06-20T05:39:28.592129Z","shell.execute_reply.started":"2021-06-20T05:38:11.595272Z","shell.execute_reply":"2021-06-20T05:39:28.590908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The date advances by index <br>\nYou can get the JSON data of the specified date by using iloc [number of lines].","metadata":{}},{"cell_type":"code","source":"training","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:28.594319Z","iopub.execute_input":"2021-06-20T05:39:28.594651Z","iopub.status.idle":"2021-06-20T05:39:28.819766Z","shell.execute_reply.started":"2021-06-20T05:39:28.594604Z","shell.execute_reply":"2021-06-20T05:39:28.818722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Func for unpack JSON\nQuoted from a [Startert Notebook](https://www.kaggle.com/ryanholbrook/getting-started-with-mlb-player-digital-engagement)","metadata":{}},{"cell_type":"code","source":"# Helper function to unpack json found in daily data\ndef unpack_json(json_str):\n    return pd.DataFrame() if pd.isna(json_str) else pd.read_json(json_str)","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:28.821161Z","iopub.execute_input":"2021-06-20T05:39:28.821497Z","iopub.status.idle":"2021-06-20T05:39:28.826304Z","shell.execute_reply.started":"2021-06-20T05:39:28.821462Z","shell.execute_reply":"2021-06-20T05:39:28.825204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# nextDayPlayerEngagement\n目的変数を含んだ重要なデータになります。<br>\nYou will predict traget1~4.","metadata":{}},{"cell_type":"code","source":"unpack_json(training['nextDayPlayerEngagement'].iloc[0])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:28.827846Z","iopub.execute_input":"2021-06-20T05:39:28.828147Z","iopub.status.idle":"2021-06-20T05:39:28.895903Z","shell.execute_reply.started":"2021-06-20T05:39:28.828118Z","shell.execute_reply":"2021-06-20T05:39:28.894509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# games\ngame information<br>\nSince the first data is 2018-2-23 and the'gameType'is S from this day, <br>\nYou can see that it contains spring training data. <br>\nAfter that, information such as the regular season is included here.","metadata":{}},{"cell_type":"code","source":"unpack_json(training['games'].iloc[53])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:28.897496Z","iopub.execute_input":"2021-06-20T05:39:28.897879Z","iopub.status.idle":"2021-06-20T05:39:28.952996Z","shell.execute_reply.started":"2021-06-20T05:39:28.897844Z","shell.execute_reply":"2021-06-20T05:39:28.951935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# rosters\nTeam list information <br>\nYou can check information such as injuries and demotion to minors","metadata":{}},{"cell_type":"code","source":"unpack_json(training['rosters'].iloc[0])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:28.954625Z","iopub.execute_input":"2021-06-20T05:39:28.955038Z","iopub.status.idle":"2021-06-20T05:39:28.986615Z","shell.execute_reply.started":"2021-06-20T05:39:28.954992Z","shell.execute_reply":"2021-06-20T05:39:28.985619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# playerBoxScores\nPlayer match results <br>\nAggregated for each match <br>\n2018-3-29 is the first data <br>\nYou can see that the regular season started from this day. <br>","metadata":{}},{"cell_type":"code","source":"unpack_json(training['playerBoxScores'].iloc[87])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:28.988860Z","iopub.execute_input":"2021-06-20T05:39:28.989157Z","iopub.status.idle":"2021-06-20T05:39:29.088448Z","shell.execute_reply.started":"2021-06-20T05:39:28.989128Z","shell.execute_reply":"2021-06-20T05:39:29.087316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# teamBoxScores\nMatch information for each team <br>\nThe number of games played on that day is different, so the number of lines varies from day to day.","metadata":{}},{"cell_type":"code","source":"unpack_json(training['teamBoxScores'].iloc[87])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:29.089919Z","iopub.execute_input":"2021-06-20T05:39:29.090217Z","iopub.status.idle":"2021-06-20T05:39:29.145089Z","shell.execute_reply.started":"2021-06-20T05:39:29.090187Z","shell.execute_reply":"2021-06-20T05:39:29.144038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# transactions\nPlayer and team transactions <br>\nIf you look at the first line, you can see that it is the trade information of the players.","metadata":{}},{"cell_type":"code","source":"unpack_json(training['transactions'].iloc[1])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:29.146416Z","iopub.execute_input":"2021-06-20T05:39:29.146718Z","iopub.status.idle":"2021-06-20T05:39:29.180068Z","shell.execute_reply.started":"2021-06-20T05:39:29.146686Z","shell.execute_reply":"2021-06-20T05:39:29.178837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# standings\nTeam ranking information <br>\nThere is data for all 30 teams","metadata":{}},{"cell_type":"code","source":"unpack_json(training['standings'].iloc[87])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:29.181445Z","iopub.execute_input":"2021-06-20T05:39:29.181736Z","iopub.status.idle":"2021-06-20T05:39:29.253410Z","shell.execute_reply.started":"2021-06-20T05:39:29.181708Z","shell.execute_reply":"2021-06-20T05:39:29.252203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# awards\nPlayer commendation information <br>\nLooking at the information on this day, since the award Season is 2017 <br>\nIt turns out that it is an award for the 2017 season","metadata":{}},{"cell_type":"code","source":"unpack_json(training['awards'].iloc[14])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:29.254934Z","iopub.execute_input":"2021-06-20T05:39:29.255347Z","iopub.status.idle":"2021-06-20T05:39:29.281148Z","shell.execute_reply.started":"2021-06-20T05:39:29.255306Z","shell.execute_reply":"2021-06-20T05:39:29.280283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# events\nData of events that happened on the field <br>\nThere are quite a lot of dimensions because there is also ball coordinate data etc.","metadata":{}},{"cell_type":"code","source":"unpack_json(training['events'].iloc[87])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:29.282427Z","iopub.execute_input":"2021-06-20T05:39:29.282703Z","iopub.status.idle":"2021-06-20T05:39:29.606513Z","shell.execute_reply.started":"2021-06-20T05:39:29.282675Z","shell.execute_reply":"2021-06-20T05:39:29.605437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# playerTwitterFollowers\nNumber of Twitter followers of players <br>\nUpdated on the first day of every month","metadata":{}},{"cell_type":"code","source":"unpack_json(training['playerTwitterFollowers'].iloc[0])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:29.607770Z","iopub.execute_input":"2021-06-20T05:39:29.608079Z","iopub.status.idle":"2021-06-20T05:39:29.644132Z","shell.execute_reply.started":"2021-06-20T05:39:29.608045Z","shell.execute_reply":"2021-06-20T05:39:29.642924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# teamTwitterFollowers\nNumber of followers on the official Twitter account of all 30 teams\n<br> As before, it is updated on the first day of every month","metadata":{}},{"cell_type":"code","source":"unpack_json(training['teamTwitterFollowers'].iloc[0])","metadata":{"execution":{"iopub.status.busy":"2021-06-20T05:39:29.645456Z","iopub.execute_input":"2021-06-20T05:39:29.645768Z","iopub.status.idle":"2021-06-20T05:39:29.676320Z","shell.execute_reply.started":"2021-06-20T05:39:29.645737Z","shell.execute_reply":"2021-06-20T05:39:29.675292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"補足情報などありましたらコメントでご指摘お願いします。","metadata":{}}]}