{"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":"**【概要】**\n\n課題は、特別なチームのプレーに対応するプレーヤーの追跡データから、実用的で実用的で斬新な洞察を生み出すことです。\nYour challenge is to generate actionable, practical, and novel insights from player tracking data that corresponds to special teams play.\n\nこれらには以下が含まれますが、これらに限定されません。\n\n1. 新しい特別チームの指標を作成します。2020年のビッグデータボウルで優勝したアルゴリズムは、NFL / NFLネットワークでオンエア配信に採用されており、今年の大会で得られる可能性のある特別チームのプレーの新しい統計が得られることを期待しています。\nCreate a new special teams metric. The winning algorithm from the 2020 Big Data Bowl has been adopted by the NFL/NFL Network for on air distribution, and we are hopeful that there could be a new stat for special teams plays that could come from this year’s competition\n\n2. 特別チームの戦略を定量化します。特別チームのコーチは、リーグで最も創造的で革新的な選手の1人です。各チームのゲームの計画を比較/対比します。どの戦略が最良の結果をもたらしますか？採用できる他の戦略は何ですか？\nQuantify special teams strategy. Special teams’ coaches are among the most creative and innovative in the league. Compare/contrast how each team game plans. Which strategies yield the best results? What are other strategies that could be adopted?\n\n\n3. 特別チームの選手をランク付けします。各チームは、さまざまなプレーヤー（ロングスナッパー、キッカー、パンター、およびその他のユーティリティ特別チームプレーヤーを含む）を採用しています。それらはどのように相互に積み重なっていますか？\nRank special teams players. Each team employs a variety of players (including longsnappers, kickers, punters, and other utility special teams players). How do they stack up with respect to one another?\n\n\n上記のリストは包括的ではなく、参加者がカバーするためのガイドとなることを意図したものでもありません。今年のコンテストでは、すべての特別チーム関連のアイデアを受け入れます。\n\n1つのアイデアをより徹底的に検討する提出は、複数のアイデアをある程度徹底的に検討する提出よりも優先されます。","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)\nimport seaborn as sns \nimport matplotlib as mpl\nfrom wordcloud import WordCloud, STOPWORDS\nimport matplotlib.pylab as plt\n\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":{"execution":{"iopub.status.busy":"2021-11-28T21:30:39.263396Z","iopub.execute_input":"2021-11-28T21:30:39.263852Z","iopub.status.idle":"2021-11-28T21:30:40.242871Z","shell.execute_reply.started":"2021-11-28T21:30:39.263767Z","shell.execute_reply":"2021-11-28T21:30:40.241993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 【Games Data】","metadata":{}},{"cell_type":"markdown","source":"ゲームデータ：にgames.csvは、各ゲームでプレーしているチームが含まれています。キー変数ですgameId。\nゲームデータ gameId：ゲーム識別子、一意（数値）\n* season：ゲームのシーズン\n* week：ゲームの週\n* gameDate：ゲームの日付（時間、mm / dd / yyyy）\n* gameTimeEastern：ゲームの開始時間（時間、HH：MM：SS、EST）\n* homeTeamAbbr：ホームチームの3文字のコード（テキスト）\n* visitorTeamAbbr：訪問チームの3文字のコード（テキスト）","metadata":{}},{"cell_type":"code","source":"df_gamedata=pd.read_csv('../input/nfl-big-data-bowl-2022/games.csv')\ndf_gamedata.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:40.244436Z","iopub.execute_input":"2021-11-28T21:30:40.244693Z","iopub.status.idle":"2021-11-28T21:30:40.276392Z","shell.execute_reply.started":"2021-11-28T21:30:40.244662Z","shell.execute_reply":"2021-11-28T21:30:40.275981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_gamedata)","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:40.277227Z","iopub.execute_input":"2021-11-28T21:30:40.277496Z","iopub.status.idle":"2021-11-28T21:30:40.282469Z","shell.execute_reply.started":"2021-11-28T21:30:40.277474Z","shell.execute_reply":"2021-11-28T21:30:40.281715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### ■search correlated columns in games.csv.","metadata":{}},{"cell_type":"code","source":"df_gamedata.corr()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:40.284428Z","iopub.execute_input":"2021-11-28T21:30:40.284897Z","iopub.status.idle":"2021-11-28T21:30:40.308142Z","shell.execute_reply.started":"2021-11-28T21:30:40.284863Z","shell.execute_reply":"2021-11-28T21:30:40.306917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pp_games = sns.pairplot(df_gamedata)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:40.311496Z","iopub.execute_input":"2021-11-28T21:30:40.312933Z","iopub.status.idle":"2021-11-28T21:30:41.964003Z","shell.execute_reply.started":"2021-11-28T21:30:40.312886Z","shell.execute_reply":"2021-11-28T21:30:41.963061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=df_gamedata.groupby('homeTeamAbbr').size()\ndf","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:41.965369Z","iopub.execute_input":"2021-11-28T21:30:41.965674Z","iopub.status.idle":"2021-11-28T21:30:41.974199Z","shell.execute_reply.started":"2021-11-28T21:30:41.965639Z","shell.execute_reply":"2021-11-28T21:30:41.973323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_gamedata.groupby('season').size()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:41.975441Z","iopub.execute_input":"2021-11-28T21:30:41.976254Z","iopub.status.idle":"2021-11-28T21:30:41.989879Z","shell.execute_reply.started":"2021-11-28T21:30:41.976219Z","shell.execute_reply":"2021-11-28T21:30:41.989318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#月ごとの試合数\n# convert integers to date \ndf_gamedata[\"gameDate\"] = pd.to_datetime(df_gamedata[\"gameDate\"])\n# extract month\ndf_gamedata['Year'] = df_gamedata[\"gameDate\"].dt.month_name()\n# extract days\ndf_gamedata['Week'] = df_gamedata[\"gameDate\"].dt.day_name()\n\nsns.set_style(\"whitegrid\")\nplt.figure(figsize=(8, 6))\nax = plt.gca()\n\nsns.countplot(x='season', data=df_gamedata, hue='Year', lw=2, ax=ax).set(title='Games in Year, Season')\nax.legend(loc='center right', bbox_to_anchor=(1.5, 0.5), ncol=1)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:41.990803Z","iopub.execute_input":"2021-11-28T21:30:41.991168Z","iopub.status.idle":"2021-11-28T21:30:42.216246Z","shell.execute_reply.started":"2021-11-28T21:30:41.991143Z","shell.execute_reply":"2021-11-28T21:30:42.215844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 【Plays Data】","metadata":{}},{"cell_type":"markdown","source":"プレイデータ：plays.csvファイルには、各ゲームのプレイレベル情報が含まれています。キー変数があるgameIdとplayId。\nデータを再生する\n* gameId：ゲーム識別子、一意（数値）\n* playId：ゲーム間で一意ではなく、識別子を再生します（数値）\n* playDescription：遊びの説明（テキスト）\n* quarter：ゲームクォーター（数値）\n* down：ダウン（数値）\n* yardsToGo：最初のダウンに必要な距離（数値）\n* possessionTeam：チームのパント、プレースキック、またはボールのキックオフ（テキスト）\n* specialTeamsPlayType：プレーの形成：エクストラポイント、フィールドゴール、キックオフまたはパント（テキスト）\n* specialTeamsPlayResult：プレーの種類に応じたプレーの特別チームの結果：ブロックされたキックの試み、ブロックされたパント、ダウン、フェアキャッチ、キックの試みは良い、キックの試みは良くない、キックオフチームの回復、マフ、非特別なチームの結果、範囲外、リターンまたはタッチバック（テキスト）\n* kickerId：プレー中のキッカー、パンター、またはキックオフスペシャリストのnflId（数値）\n* returnerId：特別なチームが戻ってきた場合、プレー中のリターナーのnflId。劇中の複数のリターナーは;（テキスト）で区切られます\n* kickBlockerId：ブロックされたフィールドゴールまたはブロックされたパントがあった場合のキックオンプレーのブロッカーのnflId（数値）\n* yardlineSide：スクリメージライン（テキスト）に対応する3文字のチームコード\n* yardlineNumber：スクリメージラインのヤードライン（数値）\n* gameClock：プレイ時間（MM：SS）\n* penaltyCodes：プレー中に発生したペナルティのNFL分類。標準のペナルティコードとそれに続くd手段は、ペナルティが防御にあったことを意味します。演劇に対する複数のペナルティは;（テキスト）で区切られます\n* penaltyJerseyNumber：各ペナルティを犯したプレーヤーのジャージ番号とチームコード。演劇に対する複数のペナルティは;（テキスト）で区切られます\n* penaltyYards：ペナルティによってpossitionTeamによって獲得されたヤード（数値）\n* preSnapHomeScore：プレー前のホームスコア（数値）\n* preSnapVisitorScore：プレー前の訪問チームのスコア（数値）\n* passResult：specialTeamsPlayResult「非特別チーム結果」の場合のプレーのスクリメージ結果（C：完全パス、I：不完全パス、S：クォーターバックサック、IN：傍受パス、R：スクランブル、' '：デザインラッシュ、テキスト）\n* kickLength：キックオフ、フィールドゴールまたはパントの空中でのキックの長さ（数値）\n* kickReturnYardage：キックオフまたはパントでリターンがあった場合にリターンチームが獲得したヤード（数値）\n* playResult：ペナルティヤード（数値）を含む、キックチームが獲得したネットヤード\n* absoluteYardlineNumber：追跡データ座標におけるボールダウンフィールドの位置（数値）","metadata":{}},{"cell_type":"code","source":"df_plays=pd.read_csv('../input/nfl-big-data-bowl-2022/plays.csv')\ndf_plays.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:42.217302Z","iopub.execute_input":"2021-11-28T21:30:42.217714Z","iopub.status.idle":"2021-11-28T21:30:42.341638Z","shell.execute_reply.started":"2021-11-28T21:30:42.217683Z","shell.execute_reply":"2021-11-28T21:30:42.341085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 【PFFScoutingData】","metadata":{}},{"cell_type":"code","source":"df_scouting=pd.read_csv('../input/nfl-big-data-bowl-2022/PFFScoutingData.csv')\ndf_scouting.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:42.344265Z","iopub.execute_input":"2021-11-28T21:30:42.345001Z","iopub.status.idle":"2021-11-28T21:30:42.451716Z","shell.execute_reply.started":"2021-11-28T21:30:42.344976Z","shell.execute_reply":"2021-11-28T21:30:42.450488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### ■search correlated columns in PFFScoutingData.csv","metadata":{}},{"cell_type":"code","source":"df_scouting.corr()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:42.452986Z","iopub.execute_input":"2021-11-28T21:30:42.453203Z","iopub.status.idle":"2021-11-28T21:30:42.467692Z","shell.execute_reply.started":"2021-11-28T21:30:42.453174Z","shell.execute_reply":"2021-11-28T21:30:42.467271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pp_scouting = sns.pairplot(df_scouting)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:42.468754Z","iopub.execute_input":"2021-11-28T21:30:42.469122Z","iopub.status.idle":"2021-11-28T21:30:47.916356Z","shell.execute_reply.started":"2021-11-28T21:30:42.469091Z","shell.execute_reply":"2021-11-28T21:30:47.915855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### ■search correlated columns in Plays.csv","metadata":{}},{"cell_type":"code","source":"df_plays.corr()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:47.917247Z","iopub.execute_input":"2021-11-28T21:30:47.917671Z","iopub.status.idle":"2021-11-28T21:30:47.948915Z","shell.execute_reply.started":"2021-11-28T21:30:47.917647Z","shell.execute_reply":"2021-11-28T21:30:47.947993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pp_plays = sns.pairplot(df_plays)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:30:47.950293Z","iopub.execute_input":"2021-11-28T21:30:47.950731Z","iopub.status.idle":"2021-11-28T21:31:33.516804Z","shell.execute_reply.started":"2021-11-28T21:30:47.950692Z","shell.execute_reply":"2021-11-28T21:31:33.515833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 【Tracking Data】","metadata":{}},{"cell_type":"markdown","source":"追跡データ：ファイルにtracking[season].csvは、シーズンのプレーヤー追跡データが含まれています[season]。主要変数でありgameId、playIdとnflId。\n追跡データ ファイルにtracking[season].csvは、シーズンのプレーヤー追跡データが含まれています[season]。\n\n* time：プレイのタイムスタンプ（時間、yyyy-mm-dd、hh：mm：ss）\n* x：フィールドの長軸に沿ったプレーヤーの位置、0〜120ヤード。以下の図1を参照してください。（数値）\n* y：フィールドの短軸に沿ったプレーヤーの位置、0〜53.3ヤード。以下の図1を参照してください。（数値）\n* s：ヤード/秒単位の速度（数値）\n* a：ヤード/秒での速度^ 2（数値）\n* dis：前の時点からの移動距離（ヤード（数値））\n* o：プレーヤーの向き（度）、0〜360度（数値）\n* dir：プレーヤーの動きの角度（度）、0〜360度（数値）\n* event：ボールスナップの瞬間、パスリリース、パスキャッチ、タックルなどのタグ付きプレイの詳細（テキスト）\n* nflId：プレーヤー間で一意のプレーヤー識別番号（数値）\n* displayName：プレイヤー名（テキスト）\n* jerseyNumber：ジャージープレーヤー数（数値）\n* position：プレイヤーポジショングループ（テキスト）\n* team：対応するプレーヤーのチーム（アウェイまたはホーム）（テキスト）\n* frameId：1から始まる各プレイのフレーム識別子（数値）\n* gameId：ゲーム識別子、一意（数値）\n* playId：ゲーム間で一意ではなく、識別子を再生します（数値）\n* playDirection：オフェンスが動いている方向（左または右）","metadata":{}},{"cell_type":"code","source":"df_t2018=pd.read_csv('../input/nfl-big-data-bowl-2022/tracking2018.csv')","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:31:33.518187Z","iopub.execute_input":"2021-11-28T21:31:33.518419Z","iopub.status.idle":"2021-11-28T21:32:07.366866Z","shell.execute_reply.started":"2021-11-28T21:31:33.518396Z","shell.execute_reply":"2021-11-28T21:32:07.366268Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_t2018.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:07.367743Z","iopub.execute_input":"2021-11-28T21:32:07.368005Z","iopub.status.idle":"2021-11-28T21:32:07.388919Z","shell.execute_reply.started":"2021-11-28T21:32:07.367982Z","shell.execute_reply":"2021-11-28T21:32:07.387943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nfrom skimage import io\nf='https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/AmFBfield.svg/1200px-AmFBfield.svg.png'\na = io.imread(f)\n# determining the height ratio\n# resize image and save\nfrom PIL import Image\nfrom matplotlib import cm\nimport matplotlib.pyplot as plt\nim = Image.fromarray(a)\nim = im.resize((120,53))\nplt.imshow(im)\nim.save('sompic.png') # Saving the resized background image","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:07.390149Z","iopub.execute_input":"2021-11-28T21:32:07.390348Z","iopub.status.idle":"2021-11-28T21:32:08.699092Z","shell.execute_reply.started":"2021-11-28T21:32:07.390316Z","shell.execute_reply":"2021-11-28T21:32:08.698551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t=df_t2018.loc[(df_t2018['time'].str.contains('2018-12-30',case=False))]","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:08.700051Z","iopub.execute_input":"2021-11-28T21:32:08.700366Z","iopub.status.idle":"2021-11-28T21:32:13.902770Z","shell.execute_reply.started":"2021-11-28T21:32:08.700338Z","shell.execute_reply":"2021-11-28T21:32:13.901808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"t.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:13.903772Z","iopub.execute_input":"2021-11-28T21:32:13.903996Z","iopub.status.idle":"2021-11-28T21:32:13.926570Z","shell.execute_reply.started":"2021-11-28T21:32:13.903969Z","shell.execute_reply":"2021-11-28T21:32:13.925852Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import time\nfrom datetime import datetime, date, time, timedelta\nt['time'][len(t)-1]\ntime_string = \"2018-12-30 21:25:32.200\"\nformat_string = \"%Y-%m-%d %H:%M:%S.%f\"\n\nfor i in range(100):\n    date_object = datetime.strptime(time_string, format_string)\n    date_object = date_object + timedelta(milliseconds=100)\n    time_string=str(date_object)\n    if '.' in time_string:\n        time_string=time_string[:-3]\n    else:\n        time_string=time_string+'.000'\n    final_string=time_string.split(' ')\n    final_string=final_string[0]+'T'+final_string[1]\n    print(final_string)\n    break\nprint(len(t['time'].unique()))\nz=t.loc[(t['time'].str.contains('2018-12-30T21:25:32.200')) & (t['gameId']==2018123000)]\nz.index = range(len(z))\nplt.rcParams[\"figure.figsize\"] = [7.50, 3.50]\nplt.rcParams[\"figure.autolayout\"] = True\nf='sompic.png'\na = io.imread(f)\n#plt.imshow(a)\nfig=plt.figure()\nax = fig.add_subplot(111)\na = io.imread(f)\nprint(len(z))\nfor i in range(len(z)):\n    ax.imshow(a)\n    if z[i:i+1]['team'][i]=='home': \n        ax.plot(z[i:i+1]['x'][i],z[i:i+1]['y'][i],'ro',color='blue')\n    elif z[i:i+1]['team'][i]=='away':\n        ax.plot(z[i:i+1]['x'][i],z[i:i+1]['y'][i],'ro',color='red')\n    else:\n        ax.plot(z[i:i+1]['x'][i],z[i:i+1]['y'][i],'ro',color='yellow')\nax.set_xlim(0, 120)\nax.set_ylim(0, 53.3)\nax.axis('on')\nleg = ax.legend(loc='upper center')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:13.927563Z","iopub.execute_input":"2021-11-28T21:32:13.927847Z","iopub.status.idle":"2021-11-28T21:32:15.243289Z","shell.execute_reply.started":"2021-11-28T21:32:13.927823Z","shell.execute_reply":"2021-11-28T21:32:15.242090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df2018=df_t2018.query('gameId==2018123000')\ndf2018.groupby('displayName').size().sort_values(ascending=True) \\\n    .plot(kind='barh', figsize=(10, 30\n                               ),\n         title='Participation time')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:15.245111Z","iopub.execute_input":"2021-11-28T21:32:15.245459Z","iopub.status.idle":"2021-11-28T21:32:16.474292Z","shell.execute_reply.started":"2021-11-28T21:32:15.245412Z","shell.execute_reply":"2021-11-28T21:32:16.473825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### ■Let's see only one person","metadata":{}},{"cell_type":"code","source":"#1人だけみてみよう\ntrack2018=df_t2018.query('playId==36 and displayName==\"Justin Tucker\"')\ntrack2018[0:3]","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:16.475129Z","iopub.execute_input":"2021-11-28T21:32:16.475416Z","iopub.status.idle":"2021-11-28T21:32:16.730443Z","shell.execute_reply.started":"2021-11-28T21:32:16.475382Z","shell.execute_reply":"2021-11-28T21:32:16.729453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plays=pd.read_csv('../input/nfl-big-data-bowl-2022/plays.csv')\ndf_plays.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:16.731688Z","iopub.execute_input":"2021-11-28T21:32:16.731958Z","iopub.status.idle":"2021-11-28T21:32:16.807678Z","shell.execute_reply.started":"2021-11-28T21:32:16.731927Z","shell.execute_reply":"2021-11-28T21:32:16.806841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 【Player Data】","metadata":{}},{"cell_type":"markdown","source":"プレーヤーデータ：このplayers.csvファイルには、追跡データファイルのいずれかに参加したプレーヤーからのプレーヤーレベルの情報が含まれています。キー変数ですnflId。\nプレーヤーデータ\n* gameId：ゲーム識別子、一意（数値）\n* playId：ゲーム間で一意ではなく、識別子を再生します（数値）\n* nflId：プレーヤー間で一意のプレーヤー識別番号（数値）\n* Height：プレーヤーの身長（テキスト）\n* Weight：プレーヤーの体重（数値）\n* birthDate：生年月日（YYYY-MM-DD）\n* collegeName：プレイヤーカレッジ（テキスト）\n* Position：プレイヤーの位置（テキスト）\n* displayName：プレイヤー名（テキスト）","metadata":{}},{"cell_type":"code","source":"df_players=pd.read_csv('../input/nfl-big-data-bowl-2022/players.csv')\ndf_players.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:16.808652Z","iopub.execute_input":"2021-11-28T21:32:16.809276Z","iopub.status.idle":"2021-11-28T21:32:16.834000Z","shell.execute_reply.started":"2021-11-28T21:32:16.809249Z","shell.execute_reply":"2021-11-28T21:32:16.832945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### ■search correlated columns in players.csv","metadata":{}},{"cell_type":"code","source":"df_players.corr()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:16.834714Z","iopub.execute_input":"2021-11-28T21:32:16.834900Z","iopub.status.idle":"2021-11-28T21:32:16.844363Z","shell.execute_reply.started":"2021-11-28T21:32:16.834879Z","shell.execute_reply":"2021-11-28T21:32:16.843586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pp_players = sns.pairplot(df_players)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:16.845623Z","iopub.execute_input":"2021-11-28T21:32:16.846252Z","iopub.status.idle":"2021-11-28T21:32:17.925436Z","shell.execute_reply.started":"2021-11-28T21:32:16.846215Z","shell.execute_reply":"2021-11-28T21:32:17.924812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Merging files ","metadata":{}},{"cell_type":"code","source":"player_plays = pd.merge(df_players, df_plays, left_on='nflId', right_on='kickerId')\nplayer_plays.head()\n","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:17.926572Z","iopub.execute_input":"2021-11-28T21:32:17.927344Z","iopub.status.idle":"2021-11-28T21:32:17.992604Z","shell.execute_reply.started":"2021-11-28T21:32:17.927309Z","shell.execute_reply":"2021-11-28T21:32:17.991812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### ■Correlation　player.csv and plays.csv","metadata":{}},{"cell_type":"code","source":"player_plays.corr()\n","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:17.995724Z","iopub.execute_input":"2021-11-28T21:32:17.995948Z","iopub.status.idle":"2021-11-28T21:32:18.031235Z","shell.execute_reply.started":"2021-11-28T21:32:17.995927Z","shell.execute_reply":"2021-11-28T21:32:18.030015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"collegs_data = df_players.groupby('collegeName').size()\n","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:18.032104Z","iopub.execute_input":"2021-11-28T21:32:18.032272Z","iopub.status.idle":"2021-11-28T21:32:18.037448Z","shell.execute_reply.started":"2021-11-28T21:32:18.032252Z","shell.execute_reply":"2021-11-28T21:32:18.036753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### ■Team size","metadata":{}},{"cell_type":"code","source":"#チームの規模\nmpl.rcParams['font.size']=12                 \nmpl.rcParams['savefig.dpi']=100             \nmpl.rcParams['figure.subplot.bottom']=.1 \n\nstopwords = set(STOPWORDS)\n\nwordcloud = WordCloud(\n                          background_color='white',\n                          stopwords=stopwords,\n                          max_words=400,\n                          max_font_size=40, \n                          random_state=42\n                         ).generate(str(df_players['collegeName']))\n\nprint(wordcloud)\nfig = plt.figure(1)\nplt.imshow(wordcloud)\nplt.axis('off')\nplt.show()\nfig.savefig(\"word1.png\", dpi=900)","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:18.038382Z","iopub.execute_input":"2021-11-28T21:32:18.038543Z","iopub.status.idle":"2021-11-28T21:32:20.251240Z","shell.execute_reply.started":"2021-11-28T21:32:18.038524Z","shell.execute_reply":"2021-11-28T21:32:20.250793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_players['collegeName'].value_counts() \\\n    .sort_values(ascending=True) \\\n    .plot(kind='barh', figsize=(10, 60\n                               ),\n         title='Count of Players by Position')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:20.252131Z","iopub.execute_input":"2021-11-28T21:32:20.252766Z","iopub.status.idle":"2021-11-28T21:32:24.465267Z","shell.execute_reply.started":"2021-11-28T21:32:20.252741Z","shell.execute_reply":"2021-11-28T21:32:24.464888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### ■Players Position Count","metadata":{}},{"cell_type":"code","source":"#どのポジションが多いかグラフで見てみよう\ndf_players['Position'].value_counts() \\\n    .sort_values(ascending=True) \\\n    .plot(kind='barh', figsize=(10, 15                               ),\n         title='Count of Players by Position')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:24.466115Z","iopub.execute_input":"2021-11-28T21:32:24.466342Z","iopub.status.idle":"2021-11-28T21:32:24.840474Z","shell.execute_reply.started":"2021-11-28T21:32:24.466322Z","shell.execute_reply":"2021-11-28T21:32:24.840053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_players)","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:24.841351Z","iopub.execute_input":"2021-11-28T21:32:24.841632Z","iopub.status.idle":"2021-11-28T21:32:24.845269Z","shell.execute_reply.started":"2021-11-28T21:32:24.841609Z","shell.execute_reply":"2021-11-28T21:32:24.844894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_players.query('collegeName==\"James Madison\"')","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:24.846145Z","iopub.execute_input":"2021-11-28T21:32:24.846309Z","iopub.status.idle":"2021-11-28T21:32:24.871240Z","shell.execute_reply.started":"2021-11-28T21:32:24.846288Z","shell.execute_reply":"2021-11-28T21:32:24.870758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_gamedata.info()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:24.872128Z","iopub.execute_input":"2021-11-28T21:32:24.872610Z","iopub.status.idle":"2021-11-28T21:32:24.885242Z","shell.execute_reply.started":"2021-11-28T21:32:24.872586Z","shell.execute_reply":"2021-11-28T21:32:24.884534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_plays[df_plays['gameId']==2018090600].head()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:24.886562Z","iopub.execute_input":"2021-11-28T21:32:24.886890Z","iopub.status.idle":"2021-11-28T21:32:24.925404Z","shell.execute_reply.started":"2021-11-28T21:32:24.886851Z","shell.execute_reply":"2021-11-28T21:32:24.924298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_t2018.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:24.927214Z","iopub.execute_input":"2021-11-28T21:32:24.927927Z","iopub.status.idle":"2021-11-28T21:32:24.952744Z","shell.execute_reply.started":"2021-11-28T21:32:24.927892Z","shell.execute_reply":"2021-11-28T21:32:24.952284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_t2018[df_t2018['displayName']=='Justin Tucker']","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:24.953735Z","iopub.execute_input":"2021-11-28T21:32:24.954908Z","iopub.status.idle":"2021-11-28T21:32:26.721168Z","shell.execute_reply.started":"2021-11-28T21:32:24.954842Z","shell.execute_reply":"2021-11-28T21:32:26.720751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### ■PlayId36 player movement","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(12, 8))\ndf_t2018.query('gameId == 2018123000 and playId == 36').groupby('team') \\\n    .plot(x='x', y='y', ax=ax, style='.')\nplt.legend().remove();\n","metadata":{"execution":{"iopub.status.busy":"2021-11-28T21:32:26.721962Z","iopub.execute_input":"2021-11-28T21:32:26.722246Z","iopub.status.idle":"2021-11-28T21:32:27.109811Z","shell.execute_reply.started":"2021-11-28T21:32:26.722224Z","shell.execute_reply":"2021-11-28T21:32:27.108819Z"},"trusted":true},"execution_count":null,"outputs":[]}]}