{"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":"2022-10-15T22:51:31.263222Z","iopub.execute_input":"2022-10-15T22:51:31.263738Z","iopub.status.idle":"2022-10-15T22:51:31.306152Z","shell.execute_reply.started":"2022-10-15T22:51:31.263636Z","shell.execute_reply":"2022-10-15T22:51:31.304759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nsns.set()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:51:31.307904Z","iopub.execute_input":"2022-10-15T22:51:31.308498Z","iopub.status.idle":"2022-10-15T22:51:32.546574Z","shell.execute_reply.started":"2022-10-15T22:51:31.308463Z","shell.execute_reply":"2022-10-15T22:51:32.544979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtypes_df = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_dtypes.csv')\ndtypes = {k: v for (k, v) in zip(dtypes_df.column, dtypes_df.dtype)}\ntrain0_df = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_0.csv', dtype=dtypes)","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:51:32.548906Z","iopub.execute_input":"2022-10-15T22:51:32.549694Z","iopub.status.idle":"2022-10-15T22:52:12.214593Z","shell.execute_reply.started":"2022-10-15T22:51:32.549642Z","shell.execute_reply":"2022-10-15T22:52:12.213052Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0_df.columns","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:12.217488Z","iopub.execute_input":"2022-10-15T22:52:12.218038Z","iopub.status.idle":"2022-10-15T22:52:12.229263Z","shell.execute_reply.started":"2022-10-15T22:52:12.217986Z","shell.execute_reply":"2022-10-15T22:52:12.227976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0_df.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:12.230880Z","iopub.execute_input":"2022-10-15T22:52:12.231343Z","iopub.status.idle":"2022-10-15T22:52:12.274293Z","shell.execute_reply.started":"2022-10-15T22:52:12.231299Z","shell.execute_reply":"2022-10-15T22:52:12.273175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0_df.query(\"(game_num == 1) and (event_id == 1002)\").set_index('event_time').team_B_scoring_within_10sec.plot()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:12.275734Z","iopub.execute_input":"2022-10-15T22:52:12.276194Z","iopub.status.idle":"2022-10-15T22:52:12.641474Z","shell.execute_reply.started":"2022-10-15T22:52:12.276152Z","shell.execute_reply":"2022-10-15T22:52:12.640133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0_df.columns","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:12.642828Z","iopub.execute_input":"2022-10-15T22:52:12.643304Z","iopub.status.idle":"2022-10-15T22:52:12.651503Z","shell.execute_reply.started":"2022-10-15T22:52:12.643265Z","shell.execute_reply":"2022-10-15T22:52:12.650260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0_df.loc[:,['ball_pos_x', 'ball_pos_y', 'ball_pos_z', 'ball_vel_x', 'ball_vel_y', 'ball_vel_z']].describe().loc[['min', 'max']]","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:12.653178Z","iopub.execute_input":"2022-10-15T22:52:12.653648Z","iopub.status.idle":"2022-10-15T22:52:13.097470Z","shell.execute_reply.started":"2022-10-15T22:52:12.653604Z","shell.execute_reply":"2022-10-15T22:52:13.096017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots()\n\ntrain0_df.assign(ball_vel_abs = np.sqrt(train0_df.ball_vel_x.pow(2).add(train0_df.ball_vel_y.pow(2).add(train0_df.ball_vel_z.pow(2))))).ball_vel_abs.plot.hist(bins=80, ax=ax)\nax.set_title('Ball absolute speed distribution')\nax.set_xlabel('Ball absolute speed');","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:13.102594Z","iopub.execute_input":"2022-10-15T22:52:13.103018Z","iopub.status.idle":"2022-10-15T22:52:14.101339Z","shell.execute_reply.started":"2022-10-15T22:52:13.102984Z","shell.execute_reply":"2022-10-15T22:52:14.099987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0_df.loc[:,['ball_pos_x', 'ball_pos_y', 'ball_pos_z', 'ball_vel_x', 'ball_vel_y', 'ball_vel_z']].describe().loc[['min', 'max']]","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:14.102888Z","iopub.execute_input":"2022-10-15T22:52:14.103390Z","iopub.status.idle":"2022-10-15T22:52:14.535961Z","shell.execute_reply.started":"2022-10-15T22:52:14.103356Z","shell.execute_reply":"2022-10-15T22:52:14.534546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total_boost = train0_df.p0_boost\nfor i in range(1,6):\n    total_boost = pd.concat([total_boost, train0_df[f'p{i}_boost']])\ntotal_boost.plot.hist(bins=80)","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:14.537807Z","iopub.execute_input":"2022-10-15T22:52:14.538329Z","iopub.status.idle":"2022-10-15T22:52:19.095410Z","shell.execute_reply.started":"2022-10-15T22:52:14.538280Z","shell.execute_reply":"2022-10-15T22:52:19.094005Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"total_boost_timer = train0_df.boost0_timer\nfor i in range(1,6):\n    total_boost_timer = pd.concat([total_boost_timer, train0_df[f'boost{i}_timer']])\ntotal_boost_timer.plot.hist(bins=80)","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:19.097350Z","iopub.execute_input":"2022-10-15T22:52:19.097784Z","iopub.status.idle":"2022-10-15T22:52:23.745174Z","shell.execute_reply.started":"2022-10-15T22:52:19.097747Z","shell.execute_reply":"2022-10-15T22:52:23.743742Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('../input/tabular-playground-series-oct-2022/test.csv')\ntest_df","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:23.746887Z","iopub.execute_input":"2022-10-15T22:52:23.747244Z","iopub.status.idle":"2022-10-15T22:52:35.683880Z","shell.execute_reply.started":"2022-10-15T22:52:23.747213Z","shell.execute_reply":"2022-10-15T22:52:35.682698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.columns","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:35.685688Z","iopub.execute_input":"2022-10-15T22:52:35.686412Z","iopub.status.idle":"2022-10-15T22:52:35.695208Z","shell.execute_reply.started":"2022-10-15T22:52:35.686365Z","shell.execute_reply":"2022-10-15T22:52:35.694088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"event_ids = dict()\nfor event_id in train0_df.game_num.unique():\n    event_ids[event_id] = train0_df.query(\"game_num == @event_id\").event_id.unique().tolist()\n\n{k: v for k, v in event_ids.items() if 0 < k < 11}","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:35.696608Z","iopub.execute_input":"2022-10-15T22:52:35.697054Z","iopub.status.idle":"2022-10-15T22:52:46.542296Z","shell.execute_reply.started":"2022-10-15T22:52:35.696986Z","shell.execute_reply":"2022-10-15T22:52:46.540746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train1_df = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_1.csv', dtype=dtypes)\ntrain1_df.game_num.unique()[:10]","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:52:46.543843Z","iopub.execute_input":"2022-10-15T22:52:46.544346Z","iopub.status.idle":"2022-10-15T22:53:26.586335Z","shell.execute_reply.started":"2022-10-15T22:52:46.544294Z","shell.execute_reply":"2022-10-15T22:53:26.585134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0_df.groupby('event_id').event_time.max().min()","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:53:26.587337Z","iopub.execute_input":"2022-10-15T22:53:26.588469Z","iopub.status.idle":"2022-10-15T22:53:26.642127Z","shell.execute_reply.started":"2022-10-15T22:53:26.588429Z","shell.execute_reply":"2022-10-15T22:53:26.640808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Notes:\n- The data is split up into 10 sections\n- There are multiple game nums starting from 1\n- For each game num there are multiple event id's:\n    - The event id is the game id plus a three digit id\n    - e.g. for game_num 8: 8001, 8002, 8003 etc\n- Game num and event id is unique for each data section, i.e. doesn't reset to 1\n- event_time starts from negative and goes to 0, end of the event\n- Ball pos has the following limits:\n    - x: +/- 80\n    - y: +/- 105\n    - z: 0-40\n- Bal vel follows a normal distribution, with a max of 105\n- Boost of each player is a percentage of boost left\n- Boost timer - Time in seconds [-10, 0] until boost orb i respawns, if player drives over an orb it gives player full boost, orbs at locations:\n    - (-61.4, -81.9)\n    - (61.4, -81.9)\n    - (-71.7, 0)\n    - (71.7, 0)\n    - (-61.4, 81.9)\n    - (61.4, 81.9)\n- player_scoring_next (train only): Which player scores at the end of the current event, in [0, 6), or -1 if the event does not end in a goal.\n- team_scoring_next (train only): Which team scores at the end of the current event (A or B), or NaN if the event does not end in a goal.\n- team_[A|B]_scoring_within_10sec (train only): [Target columns] Value of 1 if team_scoring_next == [A|B] and time_before_event is in [-10, 0], otherwise 0.\n\n- For each id in test set, which is a point in time for a single event\n- Work out probability of team A scoring and team B scoring within the next ten seconds","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(2,2, figsize=(12,8))\n\n# ax[0].scatter(train0_df.query('team_A_scoring_within_10sec == 0').ball_pos_x, train0_df.query('team_A_scoring_within_10sec == 0').ball_pos_y, marker='.', alpha=0.01, label='Not Scoring within 10 sec')\nax[0,0].scatter(train0_df.query('team_A_scoring_within_10sec == 1').ball_pos_x, train0_df.query('team_A_scoring_within_10sec == 1').ball_pos_y, marker='.', alpha=0.01) \nax[1,0].scatter(train0_df.query('team_A_scoring_within_10sec == 1').ball_pos_x, train0_df.query('team_A_scoring_within_10sec == 1').ball_pos_z, marker='.', alpha=0.01)\nax[1,1].scatter(train0_df.query('team_A_scoring_within_10sec == 1').ball_pos_y, train0_df.query('team_A_scoring_within_10sec == 1').ball_pos_z, marker='.', alpha=0.01) \n\nsns.countplot(x=train0_df.team_A_scoring_within_10sec, ax=ax[0,1])\n\nax[0,0].set_xlabel('Ball x-pos')\nax[0,0].set_ylabel('Ball y-pos')\nax[0,0].set_title('Scoring within 10 seconds')\n\nax[1,0].set_xlabel('Ball x-pos')\nax[1,0].set_ylabel('Ball z-pos')\nax[1,0].set_title('Scoring within 10 seconds')\n\nax[1,1].set_xlabel('Ball y-pos')\nax[1,1].set_ylabel('Ball z-pos')\nax[1,1].set_title('Scoring within 10 seconds')\n\nax[0,1].set_xlabel('Team A scoring within 10 sec')\nax[0,1].set_title('Amount of team A scoring within 10 sec')\nfig.suptitle('Positions and amount of scoring for A team', fontsize=16)\n\nplt.subplots_adjust(hspace=0.35)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2022-10-15T22:53:26.643954Z","iopub.execute_input":"2022-10-15T22:53:26.644785Z","iopub.status.idle":"2022-10-15T22:53:28.752876Z","shell.execute_reply.started":"2022-10-15T22:53:26.644739Z","shell.execute_reply":"2022-10-15T22:53:28.751610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(2,2, figsize=(12,8))\n\nax[0,0].scatter(train0_df.query('team_B_scoring_within_10sec == 1').ball_pos_x, train0_df.query('team_B_scoring_within_10sec == 1').ball_pos_y, marker='.', alpha=0.01) \nax[1,0].scatter(train0_df.query('team_B_scoring_within_10sec == 1').ball_pos_x, train0_df.query('team_B_scoring_within_10sec == 1').ball_pos_z, marker='.', alpha=0.01)\nax[1,1].scatter(train0_df.query('team_B_scoring_within_10sec == 1').ball_pos_y, train0_df.query('team_B_scoring_within_10sec == 1').ball_pos_z, marker='.', alpha=0.01) \n\nsns.countplot(x=train0_df.team_B_scoring_within_10sec, ax=ax[0,1])\n\nax[0,0].set_xlabel('Ball x-pos')\nax[0,0].set_ylabel('Ball y-pos')\nax[0,0].set_title('Scoring within 10 seconds')\n\nax[1,0].set_xlabel('Ball x-pos')\nax[1,0].set_ylabel('Ball z-pos')\nax[1,0].set_title('Scoring within 10 seconds')\n\nax[1,1].set_xlabel('Ball y-pos')\nax[1,1].set_ylabel('Ball z-pos')\nax[1,1].set_title('Scoring within 10 seconds')\n\nax[0,1].set_xlabel('Team B scoring within 10 sec')\nax[0,1].set_title('Amount of team B scoring within 10 sec')\nfig.suptitle('Positions and amount of scoring for B team', fontsize=16)\n\nplt.subplots_adjust(hspace=0.35)","metadata":{"_kg_hide-input":true,"jupyter":{"source_hidden":true},"execution":{"iopub.status.busy":"2022-10-15T22:53:28.754470Z","iopub.execute_input":"2022-10-15T22:53:28.754860Z","iopub.status.idle":"2022-10-15T22:53:30.787559Z","shell.execute_reply.started":"2022-10-15T22:53:28.754824Z","shell.execute_reply":"2022-10-15T22:53:30.786176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots()\n\ntrain0_df.query('team_A_scoring_within_10sec == 1').ball_pos_y.plot.hist(ax=ax, bins=40, alpha=0.5, label='Team A scoring within 10')\ntrain0_df.query('team_B_scoring_within_10sec == 1').ball_pos_y.plot.hist(ax=ax, bins=40, alpha=0.5, label='Team B scoring within 10')\n\nax.set_xlabel('Ball y-pos');\nax.set_title('Histogram of Ball y-pos and team scoring');","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:53:30.789580Z","iopub.execute_input":"2022-10-15T22:53:30.790061Z","iopub.status.idle":"2022-10-15T22:53:31.366723Z","shell.execute_reply.started":"2022-10-15T22:53:30.790018Z","shell.execute_reply":"2022-10-15T22:53:31.365572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train0_df.isna().sum()[train0_df.isna().sum() > 0]","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:53:31.368258Z","iopub.execute_input":"2022-10-15T22:53:31.368602Z","iopub.status.idle":"2022-10-15T22:53:32.131376Z","shell.execute_reply.started":"2022-10-15T22:53:31.368573Z","shell.execute_reply":"2022-10-15T22:53:32.130259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tweaked_train0_df = (train0_df\n     .assign(team_A_players_behind_ball = \n             ((train0_df.p0_pos_y < train0_df.ball_pos_y).astype('int')) + ((train0_df.p1_pos_y < train0_df.ball_pos_y).astype('int')) + ((train0_df.p2_pos_y < train0_df.ball_pos_y).astype('int')),\n            team_B_players_behind_ball = \n             ((train0_df.p3_pos_y > train0_df.ball_pos_y).astype('int')) + ((train0_df.p4_pos_y > train0_df.ball_pos_y).astype('int')) + ((train0_df.p5_pos_y > train0_df.ball_pos_y).astype('int')),\n            active_team_A_players = \n             ((~train0_df.p0_pos_x.isna()).astype('int')) + ((~train0_df.p1_pos_x.isna()).astype('int')) + ((~train0_df.p2_pos_x.isna()).astype('int')),\n            active_team_B_players = \n             ((~train0_df.p3_pos_x.isna()).astype('int')) + ((~train0_df.p4_pos_x.isna()).astype('int')) + ((~train0_df.p5_pos_x.isna()).astype('int')))\n)\n\nfig, ax = plt.subplots(1,3,figsize=(19.2, 4.8))\n\nteam_a_players_behind_df = (tweaked_train0_df\n    .groupby('team_A_players_behind_ball')\n    .agg(conceded = ('team_B_scoring_within_10sec', 'sum'),\n        scored = ('team_A_scoring_within_10sec', 'sum'),\n        total_num = ('team_B_scoring_within_10sec', 'count'))\n    .assign(no_goals = lambda df_: df_.total_num - df_.conceded - df_.scored)\n)\n\nteam_a_players_behind_df.conceded.plot.bar(ax=ax[0])\nax[0].xaxis.set_tick_params(rotation=0)\nax[0].set_title('Conceded')\nteam_a_players_behind_df.scored.plot.bar(ax=ax[1])\nax[1].xaxis.set_tick_params(rotation=0)\nax[1].set_title('Scored')\nteam_a_players_behind_df.no_goals.plot.bar(ax=ax[2])\nax[2].xaxis.set_tick_params(rotation=0)\nax[2].set_title('No Goals')","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:53:32.132766Z","iopub.execute_input":"2022-10-15T22:53:32.134827Z","iopub.status.idle":"2022-10-15T22:53:33.196381Z","shell.execute_reply.started":"2022-10-15T22:53:32.134788Z","shell.execute_reply":"2022-10-15T22:53:33.195205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(1,3,figsize=(19.2, 4.8))\n\nteam_b_players_behind_df = (tweaked_train0_df\n    .groupby('team_B_players_behind_ball')\n    .agg(conceded = ('team_A_scoring_within_10sec', 'sum'),\n        scored = ('team_B_scoring_within_10sec', 'sum'),\n        total_num = ('team_A_scoring_within_10sec', 'count'))\n    .assign(no_goals = lambda df_: df_.total_num - df_.conceded - df_.scored)\n)\n\nteam_b_players_behind_df.conceded.plot.bar(ax=ax[0])\nax[0].xaxis.set_tick_params(rotation=0)\nax[0].set_title('Conceded')\nteam_b_players_behind_df.scored.plot.bar(ax=ax[1])\nax[1].xaxis.set_tick_params(rotation=0)\nax[1].set_title('Scored')\nteam_b_players_behind_df.no_goals.plot.bar(ax=ax[2])\nax[2].xaxis.set_tick_params(rotation=0)\nax[2].set_title('No Goals')","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:53:33.198424Z","iopub.execute_input":"2022-10-15T22:53:33.199240Z","iopub.status.idle":"2022-10-15T22:53:33.870434Z","shell.execute_reply.started":"2022-10-15T22:53:33.199194Z","shell.execute_reply":"2022-10-15T22:53:33.869165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tweaked_train0_df[tweaked_train0_df.p0_pos_y.isna()].loc[:,['ball_pos_y'] + [f'p{i}_pos_y' for i in range(6)] + ['team_A_players_behind_ball', 'team_B_players_behind_ball', 'active_team_A_players', 'active_team_B_players', 'team_A_scoring_within_10sec', 'team_B_scoring_within_10sec']]","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:53:33.874696Z","iopub.execute_input":"2022-10-15T22:53:33.875098Z","iopub.status.idle":"2022-10-15T22:53:33.964400Z","shell.execute_reply.started":"2022-10-15T22:53:33.875062Z","shell.execute_reply":"2022-10-15T22:53:33.963126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tweaked_train0_df.groupby('active_team_A_players').agg({'team_A_scoring_within_10sec': 'mean', 'team_B_scoring_within_10sec': 'mean'})","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:53:33.966489Z","iopub.execute_input":"2022-10-15T22:53:33.966959Z","iopub.status.idle":"2022-10-15T22:53:34.053818Z","shell.execute_reply.started":"2022-10-15T22:53:33.966895Z","shell.execute_reply":"2022-10-15T22:53:34.052628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tweaked_train0_df.groupby('active_team_B_players').agg({'team_A_scoring_within_10sec': 'mean', 'team_B_scoring_within_10sec': 'mean'})","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:53:34.055297Z","iopub.execute_input":"2022-10-15T22:53:34.055624Z","iopub.status.idle":"2022-10-15T22:53:34.139000Z","shell.execute_reply.started":"2022-10-15T22:53:34.055595Z","shell.execute_reply":"2022-10-15T22:53:34.137662Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(tweaked_train0_df\n    .assign(diff_players = tweaked_train0_df.active_team_A_players - tweaked_train0_df.active_team_B_players)\n    .groupby('diff_players')\n    .agg({'team_A_scoring_within_10sec': 'mean', 'team_B_scoring_within_10sec': 'mean'})\n)","metadata":{"execution":{"iopub.status.busy":"2022-10-15T22:53:34.140571Z","iopub.execute_input":"2022-10-15T22:53:34.141075Z","iopub.status.idle":"2022-10-15T22:53:34.429142Z","shell.execute_reply.started":"2022-10-15T22:53:34.141022Z","shell.execute_reply":"2022-10-15T22:53:34.427990Z"},"trusted":true},"execution_count":null,"outputs":[]}]}