{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Is this Sean Marks last chance to build a good team in Brooklyn? #\n",
"*July 9. 2024*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I'm a Brooklyn Nets fan, and with the [2nd worst loss in Nets Franchise history against the Celtics](https://www.nydailynews.com/2024/02/14/nets-embarrassed-celtics-mikal-bridges-jayson-tatum-jacque-vaughn/) this past season, I wanted to assess whether Nets GM Sean Mark, who is approaching 10 years of being the Nets GM, knows what he is doing and whether or not we're headed in the right direction. \n",
"\n",
"**Objective:** Explore various metrics that encapsulate whether or not an NBA team's GM is doing a good job or not:\n",
"- Win Loss Record\n",
"- Playoff Appearances\n",
"- Fan Sentiment Analysis\n",
"- Salary Cap Management\n",
"- Draft Success Rate\n",
"- Trade Impact Analysis\n",
"\n",
"### 1. Win-Loss Record since taking the GM role ###"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"# import the necessary libraries\n",
"# It'd be interesting to see how many all-stars have been involved in those wins since that GM has been there\n",
"import pandas as pd\n",
"import numpy as np\n",
"import requests\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"import plotly.express as px\n",
"import plotly.io as pio\n",
"\n",
"# This ensures Plotly output works in multiple places:\n",
"# plotly_mimetype: VS Code notebook UI\n",
"# notebook: \"Jupyter: Export to HTML\" command in VS Code\n",
"# See https://plotly.com/python/renderers/#multiple-renderers\n",
"pio.renderers.default = \"plotly_mimetype+notebook\"\n",
"import plotly.graph_objs as go\n",
"from nba_api.stats.static import players, teams\n",
"from nba_api.stats.endpoints import leaguegamefinder, playbyplay, playbyplayv2, playercareerstats\n",
"from nba_api.stats.library.parameters import Season, SeasonType\n",
"\n",
"import os\n",
"os.add_dll_directory(r\"C:\\Program Files\\GTK3-Runtime Win64\\bin\")\n",
"from matplotlib.patches import Arc\n",
"import itertools\n",
"from PIL import Image\n",
"import time\n",
"from py_ball import synergy, image"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"\n",
"nba_general_managers = {\n",
" 'Landry Fields (Atlanta Hawks)': '2022-06-13', #done\n",
" 'Brad Stevens (Boston Celtics)': '2021-07-04', #done\n",
" 'Sean Marks (Brooklyn Nets)': '2016-02-18', #done\n",
" 'Mitch Kupchak (Charlotte Hornets)': '2018-04-08', #done\n",
" 'Marc Eversley (Chicago Bulls)': '2020-04-01', #done\n",
" 'Mike Gansey (Cleveland Cavaliers)': '2022-02-23', #done\n",
" 'Nico Harrison (Dallas Mavericks)': '2021-06-28', #done\n",
" 'Calvin Booth (Denver Nuggets)': '2020-07-07', #done\n",
" 'Troy Weaver (Detroit Pistons)': '2020-06-18', #done\n",
" 'Mike Dunleavy Jr. (Golden State Warriors)': '2023-06-16', #done\n",
" 'Rafael Stone (Houston Rockets)': '2020-10-15', #done\n",
" 'Kevin Pritchard (Indiana Pacers)': '2017-06-29',#done\n",
" 'Trent Redden (Los Angeles Clippers)': '2023-06-01', #done\n",
" 'Rob Pelinka (Los Angeles Lakers)': '2017-03-07', #done\n",
" 'Zach Kleiman (Memphis Grizzlies)': '2019-04-11', \n",
" 'Andy Elisburg (Miami Heat)': '2013-09-28',\n",
" 'Jon Horst (Milwaukee Bucks)': '2017-06-16',\n",
" 'Gersson Rosas (Minnesota Timberwolves)': '2019-05-01',\n",
" 'David Griffin (New Orleans Pelicans)': '2019-04-17',\n",
" 'Leon Rose (New York Knicks)': '2020-03-02',\n",
" 'Sam Presti (Oklahoma City Thunder)': '2007-06-07',\n",
" 'Jeff Weltman (Orlando Magic)': '2017-05-23',\n",
" 'Daryl Morey (Philadelphia 76ers)': '2020-11-02',\n",
" 'James Jones (Phoenix Suns)': '2019-04-11',\n",
" 'Neil Olshey (Portland Trail Blazers)': '2012-06-04',\n",
" 'Monte McNair (Sacramento Kings)': '2020-09-17',\n",
" 'Brian Wright (San Antonio Spurs)': '2019-07-24',\n",
" 'Bobby Webster (Toronto Raptors)': '2017-06-28',\n",
" 'Justin Zanik (Utah Jazz)': '2019-07-22',\n",
" 'Tommy Sheppard (Washington Wizards)': '2019-07-22'\n",
"}\n",
"\n",
"nba_team_colors = {\n",
" \"Atlanta Hawks\": \"Red\",\n",
" \"Boston Celtics\": \"Green\",\n",
" \"Brooklyn Nets\": \"Black\",\n",
" \"Charlotte Hornets\": \"Teal\",\n",
" \"Chicago Bulls\": \"Red\",\n",
" \"Cleveland Cavaliers\": \"Wine\",\n",
" \"Dallas Mavericks\": \"Blue\",\n",
" \"Denver Nuggets\": \"Navy\",\n",
" \"Detroit Pistons\": \"Red\",\n",
" \"Golden State Warriors\": \"Royal Blue\",\n",
" \"Houston Rockets\": \"Red\",\n",
" \"Indiana Pacers\": \"Navy\",\n",
" \"Los Angeles Clippers\": \"Red\",\n",
" \"Los Angeles Lakers\": \"Purple\",\n",
" \"Memphis Grizzlies\": \"Navy\",\n",
" \"Miami Heat\": \"Red\",\n",
" \"Milwaukee Bucks\": \"Green\",\n",
" \"Minnesota Timberwolves\": \"Blue\",\n",
" \"New Orleans Pelicans\": \"Navy\",\n",
" \"New York Knicks\": \"Blue\",\n",
" \"Oklahoma City Thunder\": \"Blue\",\n",
" \"Orlando Magic\": \"Blue\",\n",
" \"Philadelphia 76ers\": \"Blue\",\n",
" \"Phoenix Suns\": \"Purple\",\n",
" \"Portland Trail Blazers\": \"Red\",\n",
" \"Sacramento Kings\": \"Purple\",\n",
" \"San Antonio Spurs\": \"Black\",\n",
" \"Toronto Raptors\": \"Red\",\n",
" \"Utah Jazz\": \"Navy\",\n",
" \"Washington Wizards\": \"Red\"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"# Splitting keys into owner name and team name, and creating lists for each\n",
"owner_names = []\n",
"team_names = []\n",
"dates = []\n",
"for key, value in nba_general_managers.items():\n",
" owner_name, team_name = key.split(\" (\")\n",
" team_name = team_name[:-1] # Removing the closing parenthesis\n",
" owner_names.append(owner_name)\n",
" team_names.append(team_name)\n",
" dates.append(value)\n",
"\n",
"# Creating DataFrame\n",
"df = pd.DataFrame({\n",
" 'full_name': team_names,\n",
" 'general_manager': owner_names,\n",
" 'gm_start_date': dates\n",
"})\n",
"\n",
"# get_teams returns a list of 30 dictionaries, each an NBA team.\n",
"nba_teams = pd.DataFrame(teams.get_teams())\n",
"\n",
"merged_nba_teams = pd.merge(df, nba_teams, on ='full_name', how='right')\n",
"\n",
"wins = []\n",
"losses = []\n",
"win_perc = []\n",
"\n",
"for index, row in merged_nba_teams.iterrows():\n",
" gamefinder = leaguegamefinder.LeagueGameFinder(team_id_nullable=row['id'])\n",
" historical_games = gamefinder.get_data_frames()[0]\n",
" # historical_games['OPP_TEAM_ABBREVIATION'] = historical_games['MATCHUP'].str.extract(r'[@vs\\.] ?(\\w+)$')\n",
" # historical_games['LOCATION'] = np.where(historical_games['MATCHUP'].str.contains('@'), 'Home', 'Away')\n",
" gm_wl = historical_games[historical_games['GAME_DATE'] >= row['gm_start_date']]\n",
" win_loss_counts = gm_wl.groupby('WL').size()\n",
" total_wins = win_loss_counts.get('W', 0)\n",
" total_losses = win_loss_counts.get('L', 0)\n",
" winning_percentage = round(total_wins / (total_wins + total_losses) * 100, 2)\n",
"\n",
" wins.append(total_wins)\n",
" losses.append(total_losses)\n",
" win_perc.append(winning_percentage)\n",
"\n",
"merged_nba_teams['wins_since'] = wins\n",
"merged_nba_teams['losses_since'] = losses\n",
"merged_nba_teams['winning_percentage'] = win_perc\n",
"merged_nba_teams['days_of_ownership'] = (pd.Timestamp.today() - pd.to_datetime(merged_nba_teams['gm_start_date'])).dt.days\n",
"\n",
"\n",
"# Gather team logos using pyball image and append it to df\n",
"list_of_logos = []\n",
"for team_id in merged_nba_teams['id']:\n",
" logo = image.Logo(league='NBA', team_id=team_id).image\n",
" logo = logo.convert('RGBA')\n",
" logo.thumbnail((250, 250), Image.LANCZOS)\n",
" list_of_logos.append(logo)\n",
"merged_nba_teams['logo'] = list_of_logos"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
" \n",
" "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.plotly.v1+json": {
"config": {
"plotlyServerURL": "https://plot.ly"
},
"data": [
{
"alignmentgroup": "True",
"customdata": [
[
"Hawks"
],
[
"Celtics"
],
[
"Cavaliers"
],
[
"Pelicans"
],
[
"Bulls"
],
[
"Mavericks"
],
[
"Nuggets"
],
[
"Warriors"
],
[
"Rockets"
],
[
"Clippers"
],
[
"Lakers"
],
[
"Heat"
],
[
"Bucks"
],
[
"Timberwolves"
],
[
"Nets"
],
[
"Knicks"
],
[
"Magic"
],
[
"Pacers"
],
[
"76ers"
],
[
"Suns"
],
[
"Trail Blazers"
],
[
"Kings"
],
[
"Spurs"
],
[
"Thunder"
],
[
"Raptors"
],
[
"Jazz"
],
[
"Grizzlies"
],
[
"Wizards"
],
[
"Pistons"
],
[
"Hornets"
]
],
"hovertemplate": "general_manager=%{x}
winning_percentage=%{marker.color}
nickname=%{customdata[0]}
| \n", " | SEASON_ID | \n", "TEAM_ID | \n", "TEAM_ABBREVIATION | \n", "TEAM_NAME | \n", "GAME_ID | \n", "GAME_DATE | \n", "MATCHUP | \n", "WL | \n", "MIN | \n", "PTS | \n", "... | \n", "DREB | \n", "REB | \n", "AST | \n", "STL | \n", "BLK | \n", "TOV | \n", "PF | \n", "PLUS_MINUS | \n", "OPP_TEAM_ABBREVIATION | \n", "LOCATION | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "22024 | \n", "1610612751 | \n", "BKN | \n", "Brooklyn Nets | \n", "1522400072 | \n", "2024-07-21 | \n", "BKN vs. CHA | \n", "L | \n", "201 | \n", "90 | \n", "... | \n", "26 | \n", "31 | \n", "18 | \n", "11 | \n", "5 | \n", "20 | \n", "19 | \n", "-8.0 | \n", "CHA | \n", "Away | \n", "
| 1 | \n", "22024 | \n", "1610612751 | \n", "BKN | \n", "Brooklyn Nets | \n", "1522400049 | \n", "2024-07-18 | \n", "BKN vs. ORL | \n", "W | \n", "201 | \n", "102 | \n", "... | \n", "29 | \n", "34 | \n", "25 | \n", "6 | \n", "1 | \n", "9 | \n", "14 | \n", "2.0 | \n", "ORL | \n", "Away | \n", "
| 2 | \n", "22024 | \n", "1610612751 | \n", "BKN | \n", "Brooklyn Nets | \n", "1522400031 | \n", "2024-07-16 | \n", "BKN vs. NYK | \n", "W | \n", "200 | \n", "92 | \n", "... | \n", "22 | \n", "34 | \n", "19 | \n", "13 | \n", "0 | \n", "14 | \n", "23 | \n", "-1.8 | \n", "NYK | \n", "Away | \n", "
| 3 | \n", "22024 | \n", "1610612751 | \n", "BKN | \n", "Brooklyn Nets | \n", "1522400017 | \n", "2024-07-14 | \n", "BKN @ LAC | \n", "L | \n", "201 | \n", "78 | \n", "... | \n", "16 | \n", "27 | \n", "13 | \n", "6 | \n", "6 | \n", "14 | \n", "24 | \n", "-17.4 | \n", "LAC | \n", "Home | \n", "
| 4 | \n", "22024 | \n", "1610612751 | \n", "BKN | \n", "Brooklyn Nets | \n", "1522400005 | \n", "2024-07-12 | \n", "BKN @ IND | \n", "W | \n", "220 | \n", "97 | \n", "... | \n", "27 | \n", "40 | \n", "21 | \n", "17 | \n", "11 | \n", "21 | \n", "32 | \n", "0.4 | \n", "IND | \n", "Home | \n", "
5 rows × 30 columns
\n", "| \n", " | SEASON | \n", "OPP_TEAM_ABBREVIATION | \n", "Wins | \n", "Losses | \n", "
|---|---|---|---|---|
| 0 | \n", "1983 | \n", "MIL | \n", "2.0 | \n", "4.0 | \n", "
| 1 | \n", "1983 | \n", "PHL | \n", "3.0 | \n", "2.0 | \n", "
| 2 | \n", "1984 | \n", "DET | \n", "0.0 | \n", "3.0 | \n", "
| 3 | \n", "1985 | \n", "MIL | \n", "0.0 | \n", "3.0 | \n", "
| 4 | \n", "1991 | \n", "CLE | \n", "1.0 | \n", "3.0 | \n", "
| 5 | \n", "1992 | \n", "CLE | \n", "2.0 | \n", "3.0 | \n", "
| 6 | \n", "1993 | \n", "NYK | \n", "1.0 | \n", "3.0 | \n", "
| 7 | \n", "1997 | \n", "CHI | \n", "0.0 | \n", "3.0 | \n", "
| 8 | \n", "2001 | \n", "BOS | \n", "4.0 | \n", "2.0 | \n", "
| 9 | \n", "2001 | \n", "CHH | \n", "4.0 | \n", "1.0 | \n", "
| 10 | \n", "2001 | \n", "IND | \n", "3.0 | \n", "2.0 | \n", "
| 11 | \n", "2001 | \n", "LAL | \n", "0.0 | \n", "4.0 | \n", "
| 12 | \n", "2002 | \n", "BOS | \n", "4.0 | \n", "0.0 | \n", "
| 13 | \n", "2002 | \n", "DET | \n", "4.0 | \n", "0.0 | \n", "
| 14 | \n", "2002 | \n", "MIL | \n", "4.0 | \n", "2.0 | \n", "
| 15 | \n", "2002 | \n", "SAS | \n", "2.0 | \n", "4.0 | \n", "
| 16 | \n", "2003 | \n", "DET | \n", "3.0 | \n", "4.0 | \n", "
| 17 | \n", "2003 | \n", "NYK | \n", "4.0 | \n", "0.0 | \n", "
| 18 | \n", "2004 | \n", "MIA | \n", "0.0 | \n", "4.0 | \n", "
| 19 | \n", "2005 | \n", "IND | \n", "4.0 | \n", "2.0 | \n", "
| 20 | \n", "2005 | \n", "MIA | \n", "1.0 | \n", "4.0 | \n", "
| 21 | \n", "2006 | \n", "CLE | \n", "2.0 | \n", "4.0 | \n", "
| 22 | \n", "2006 | \n", "TOR | \n", "4.0 | \n", "2.0 | \n", "
| 23 | \n", "2012 | \n", "CHI | \n", "3.0 | \n", "4.0 | \n", "
| 24 | \n", "2013 | \n", "MIA | \n", "1.0 | \n", "4.0 | \n", "
| 25 | \n", "2013 | \n", "TOR | \n", "4.0 | \n", "3.0 | \n", "
| 26 | \n", "2014 | \n", "ATL | \n", "2.0 | \n", "4.0 | \n", "
| 27 | \n", "2018 | \n", "PHI | \n", "1.0 | \n", "4.0 | \n", "
| 28 | \n", "2019 | \n", "TOR | \n", "0.0 | \n", "4.0 | \n", "
| 29 | \n", "2020 | \n", "BOS | \n", "4.0 | \n", "1.0 | \n", "
| 30 | \n", "2020 | \n", "MIL | \n", "3.0 | \n", "4.0 | \n", "
| 31 | \n", "2021 | \n", "BOS | \n", "0.0 | \n", "4.0 | \n", "
| 32 | \n", "2022 | \n", "PHI | \n", "0.0 | \n", "4.0 | \n", "