{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 in \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 \"../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# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport seaborn as sns\nimport collections","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Team Data\n\nTeam name and Team ID. "},{"metadata":{"trusted":true},"cell_type":"code","source":"WTeams = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WTeams.csv')\n\nWTeams","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Seasons\n\n+ Day\n+ Region"},{"metadata":{"trusted":true},"cell_type":"code","source":"WSeasons = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WSeasons.csv')\n\nWSeasons","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### TouneySeeds"},{"metadata":{"trusted":true},"cell_type":"code","source":"WTouneySeeds = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WNCAATourneySeeds.csv')\n\nWTouneySeeds","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### RegularSeasonResults\n\n**Attention**\n+ all games played from DayNum 0 through 132\n+ 'RegularSeasonGame' are defined to be all games played on DayNum=132 or earlier (DayNum = 133 is Selection Monday)\n\n+ WTeamID : This is id number of the team that won the game\n+ WScore : This is the number of points scored by the winning team\n+ LTeamID : looser\n+ LScore : points scored by the lost the game\n+ NumOT : overtime\n+ WLoc : this is the \"location\" of the winning team. If the winning team was the home team, this value will be \"H\". If the winning team was the visiting team, this value will be \"A\". If it was played on a neutral court, then this value will be \"N\"."},{"metadata":{"trusted":true},"cell_type":"code","source":"SeasonResults = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WRegularSeasonCompactResults.csv')\n\nSeasonResults","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### TourneyCompact\n\n2017 season through 2020 season:\n+ Round 1 = days 137/138 (Fri/Sat)\n+ Round 2 = days 139/140 (Sun/Mon)\n+ Round 3 = days 144/145 (Sweet Sixteen, Fri/Sat)\n+ Round 4 = days 146/147 (Elite Eight, Sun/Mon)\n+ National Seminfinal = day 151 (Fri)\n+ National Final = day 153 (Sun)\n\n2015 season and 2016 season:\n+ Round 1 = days 137/138 (Fri/Sat)\n+ Round 2 = days 139/140 (Sun/Mon)\n+ Round 3 = days 144/145 (Sweet Sixteen, Fri/Sat)\n+ Round 4 = days 146/147 (Elite Eight, Sun/Mon)\n+ National Seminfinal = day 153 (Sun)\n+ National Final = day 155 (Tue)\n\n2003 season through 2014 season:\n+ Round 1 = days 138/139 (Sat/Sun)\n+ Round 2 = days 140/141 (Mon/Tue)\n+ Round 3 = days 145/146 (Sweet Sixteen, Sat/Sun)\n+ Round 4 = days 147/148 (Elite Eight, Mon/Tue)\n+ National Seminfinal = day 153 (Sun)\n+ National Final = day 155 (Tue)\n\n1998 season through 2002 season:\n+ Round 1 = days 137/138 (Fri/Sat)\n+ Round 2 = days 139/140 (Sun/Mon)\n+ Round 3 = day 145 only (Sweet Sixteen, Sat)\n+ Round 4 = day 147 only (Elite Eight, Mon)\n+ National Seminfinal = day 151 (Fri)\n+ National Final = day 153 (Sun)"},{"metadata":{"trusted":true},"cell_type":"code","source":"TouneyResults = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WNCAATourneyCompactResults.csv')\n\nTouneyResults","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### TeamBoxScore\nThis section provides game-by-game stats at a team level (free throws attempted, defensive rebounds, turnovers, etc.) for all regular season.\n+ WFGM - field goals made (by the winning team)\n+ WFGA - field goals attempted (by the winning team)\n+ WFGM3 - three pointers made (by the winning team)\n+ WFGA3 - three pointers attempted (by the winning team)\n+ WFTM - free throws made (by the winning team)\n+ WFTA - free throws attempted (by the winning team)\n+ WOR - offensive rebounds (pulled by the winning team)\n+ WDR - defensive rebounds (pulled by the winning team)\n+ + + WAst - assists (by the winning team)\n+ + WTO - turnovers committed (by the winning team)\n+ WStl - steals (accomplished by the winning team)\n+ WBlk - blocks (accomplished by the winning team)\n+ WPF - personal fouls committed (by the winning team)"},{"metadata":{"trusted":true},"cell_type":"code","source":"RegularDetailedResults = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WRegularSeasonDetailedResults.csv')\n\nRegularDetailedResults","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"NCAADetailedResults = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WNCAATourneyDetailedResults.csv')\n\nNCAADetailedResults","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Geography\nThis section provides city locations of all regular season, conference tournament, and NCAA tournament games since the 2009-19 season.\n\n### Cities\nThis file provides a master list of cities that have been locations for games played.\n\n### GameCities\nThis file identifies all games, starting with the 2010 season, along with the city that the game was played in."},{"metadata":{"trusted":true},"cell_type":"code","source":"Cities = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/Cities.csv')\n\nCities","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"GameCities = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WGameCities.csv')\n\nGameCities","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Play-by-play\nThis section proveides play-by-play event logs for more than 99% of each year's regular season and NCAA tournament, and secondary tournament women's games since the 2014-15 season - including plays by individual players.\n\n+ EventID\n+ Season\n+ DayNum\n+ WTeamID\n+ LTeamID\n+ WFinalScore = WScore\n+ LFinalScore = LScore\n+ WCurrentScore\n+ LCurrentSCore\n+ ELapsedSeconds : This is the number of seconds that have elapsed from the start of the game until the event occurred.\n+ EventTeamID\n+ EventPlayerID \n+ EventType\n+ EventSubType\n\n### Players\n+ PlayerID\n+ LastName\n+ TeamID"},{"metadata":{"trusted":true},"cell_type":"code","source":"WEvents2015 = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WEvents2015.csv')\nWEvents2016 = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WEvents2016.csv')\nWEvents2017 = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WEvents2017.csv')\nWEvents2018 = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WEvents2018.csv')\nWEvents2019 = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WEvents2019.csv')\n\nWEvents2015","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Player = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WPlayers.csv')\n\nPlayer","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Supplements\nThis section contains additional supporting information, including alternative team name spellings and representations of bracket structure.\n\n### TeamSpelling\n+ TeamNameSpelling : This is the spelling of the team name.\n+ TeamID\n\n### Slots\nThis file identifies th mechanism by which teams  are paired against each other, depending upon their seeds, as the tounament proceeds through its rounds. It can be of use in identifying, for a given historical game, what round it occurred in, and what the seeds/slots were for the two teams (the meaning of \"slots\" is described below).\n+ slots :  this uniquely identifies one of the tournament games. It is a four-character string, where the first two characters tell you which round the game is (R1, R2, R3, R4, R5, or R6) and the second two characters tell you the expected seed of the favored team. Thus the first row is R1W1, identifying the Round 1 game played in the W bracket, where the favored team is the 1 seed. As a further example, the R2W1 slot indicates the Round 2 game that would have the 1 seed from the W bracket, assuming that all favored teams have won up to that point. The slot names are different for the final two rounds, where R5WX identifies the national semifinal game between the winners of regions W and X, and R5YZ identifies the national semifinal game between the winners of regions Y and Z, and R6CH identifies the championship game. The \"slot\" value is used in other columns in order to represent the advancement and pairings of winners of previous games.\n\n+ StrongSeed : This indicates the expected stronger-seeded team that playsin this game.\n+ WeakSeed\n\n### Conferenses\nThis file indicates the Division 1 conferences that have existed over the years since 1985.\n+ ConfAbbrev : shorter text name\n+ Description : longer text name\n\n### TeamConferences\nThis file indicates the conference affiliations for each team during each season. Some conferences have changed their names from year to year, and/or changed which teams are part of the conference.\n+ season\n+ TeamID\n+ ConfAbbrev"},{"metadata":{"trusted":true},"cell_type":"code","source":"Slots = pd.read_csv('/kaggle/input/google-cloud-ncaa-march-madness-2020-division-1-womens-tournament/WDataFiles_Stage1/WNCAATourneySlots.csv')\n\nSlots","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Data Wrangling"},{"metadata":{"trusted":true},"cell_type":"code","source":"WTouneySeeds","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"WTeams","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pd.merge(WTouneySeeds,WTeams,on='TeamID').set_index('TeamID')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"SeasonResults","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Visualization\n### SeasonData\nbasketball performance indicators according to home/away games and winning and losing teams"},{"metadata":{"trusted":true},"cell_type":"code","source":"collections.Counter(SeasonResults['WLoc'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"SeasonResults['WLoc'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"SeasonResults['WLoc'].value_counts().plot(kind='bar')\nplt.legend()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"SeasonResults['WScore'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig,ax=plt.subplots(1,figsize=(15,10))\n\nsns.kdeplot(SeasonResults['WScore'],color='green',shade=True,ax=ax)\nsns.kdeplot(SeasonResults['LScore'],shade=True,ax=ax)\n\nplt.legend()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"SortWScore= SeasonResults.sort_values('WScore',ascending=False).head(10)\n\nSortWScore","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.barplot(x='WScore',y='WTeamID',data=SortWScore,palette='Set3_r',orient=\"h\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig,ax=plt.subplots(1,figsize=(15,10))\n\nsns.kdeplot(SeasonResults.loc[(SeasonResults['WLoc']=='H'),'WScore'],color='green',shade=True,ax=ax)\nsns.kdeplot(SeasonResults.loc[(SeasonResults['WLoc']=='A'),'WScore'],color='red',shade=True,ax=ax)\nsns.kdeplot(SeasonResults.loc[(SeasonResults['WLoc']=='N'),'WScore'],color='blue',shade=True,ax=ax)\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"WScoreFrequency = SeasonResults['WScore'].value_counts()\nWScoreFrequency.index.names = ['WScore']\n\nLScoreFrequency = SeasonResults['LScore'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"SortW = SeasonResults.sort_values('WScore',ascending=False)\nSortL = SeasonResults.sort_values('LScore',ascending=False)\n\nSortW['WScore'].plot(kind='hist',bins=50,label='WScore',alpha=0.5)\nSortL['LScore'].plot(kind='hist',bins=50,label='LScore',alpha=0.5)\nplt.title('Score Frequency')\nplt.legend()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"SeasonResults.groupby(['WTeamID','LTeamID']).size().unstack().fillna(0).style.background_gradient(axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"SeasonResults['counter']=1\nSeasonResults.groupby('WTeamID')['counter'] \\\n    .count() \\\n    .sort_values() \\\n    .tail(20) \\\n    .plot(kind='barh',figsize=(15,8),xlim=(400,680))\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Event Data"},{"metadata":{"trusted":true},"cell_type":"code","source":"WEvents2015.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"WEvents2015['counter']=1\nWEvents2015.groupby('EventType')['counter'] \\\n    .sum() \\\n    .sort_values(ascending=False)\\\n    .plot(kind='bar',figsize=(15,5),title='Event Type Frequency 2015')\nplt.show()","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}