{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "worldwide-blood",
   "metadata": {},
   "source": [
    "# Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "understanding-numbers",
   "metadata": {},
   "source": [
    "I will research 3 different questions I had while looking at the NBA data.  I will first find who the better player is between LeBron James and Kevin Durant and then find who the best players are on offense and defense.  All of the data I will be using will come from the 2014-2022 NBA seasons.  This project will be able to give valuable insight to an NBA front office telling them who they should try to acquire in the offseason."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "greater-circular",
   "metadata": {},
   "source": [
    "## Overarching Question: Who are some of the best players in the NBA from 2014-2022?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "appreciated-testimony",
   "metadata": {},
   "source": [
    "I want to look at this because I have played basketball most of my life and enjoy watching the NBA.  I enjoy looking at NBA players' stats in my free time, so this was very interesting to me.  I want to see who some of the best players are on offense and defense in the NBA."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "permanent-pollution",
   "metadata": {},
   "source": [
    "# Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "technical-evans",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "overhead-sigma",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "file_name = \"modern_RAPTOR_by_player.csv\"\n",
    "dataset_path = \"data/\" + file_name\n",
    "df = pd.read_csv(dataset_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "heated-blade",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>player_name</th>\n",
       "      <th>player_id</th>\n",
       "      <th>season</th>\n",
       "      <th>poss</th>\n",
       "      <th>mp</th>\n",
       "      <th>raptor_box_offense</th>\n",
       "      <th>raptor_box_defense</th>\n",
       "      <th>raptor_box_total</th>\n",
       "      <th>raptor_onoff_offense</th>\n",
       "      <th>raptor_onoff_defense</th>\n",
       "      <th>...</th>\n",
       "      <th>raptor_offense</th>\n",
       "      <th>raptor_defense</th>\n",
       "      <th>raptor_total</th>\n",
       "      <th>war_total</th>\n",
       "      <th>war_reg_season</th>\n",
       "      <th>war_playoffs</th>\n",
       "      <th>predator_offense</th>\n",
       "      <th>predator_defense</th>\n",
       "      <th>predator_total</th>\n",
       "      <th>pace_impact</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Alex Abrines</td>\n",
       "      <td>abrinal01</td>\n",
       "      <td>2017</td>\n",
       "      <td>2387</td>\n",
       "      <td>1135</td>\n",
       "      <td>0.745505</td>\n",
       "      <td>-0.372938</td>\n",
       "      <td>0.372567</td>\n",
       "      <td>-0.418553</td>\n",
       "      <td>-3.857011</td>\n",
       "      <td>...</td>\n",
       "      <td>0.543421</td>\n",
       "      <td>-1.144832</td>\n",
       "      <td>-0.601411</td>\n",
       "      <td>1.249008</td>\n",
       "      <td>1.447708</td>\n",
       "      <td>-0.198700</td>\n",
       "      <td>0.077102</td>\n",
       "      <td>-1.038677</td>\n",
       "      <td>-0.961575</td>\n",
       "      <td>0.326413</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Alex Abrines</td>\n",
       "      <td>abrinal01</td>\n",
       "      <td>2018</td>\n",
       "      <td>2546</td>\n",
       "      <td>1244</td>\n",
       "      <td>0.317549</td>\n",
       "      <td>-1.725325</td>\n",
       "      <td>-1.407776</td>\n",
       "      <td>-1.291727</td>\n",
       "      <td>-0.049694</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.020826</td>\n",
       "      <td>-1.502642</td>\n",
       "      <td>-1.523468</td>\n",
       "      <td>0.777304</td>\n",
       "      <td>0.465912</td>\n",
       "      <td>0.311392</td>\n",
       "      <td>-0.174621</td>\n",
       "      <td>-1.112625</td>\n",
       "      <td>-1.287247</td>\n",
       "      <td>-0.456141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Alex Abrines</td>\n",
       "      <td>abrinal01</td>\n",
       "      <td>2019</td>\n",
       "      <td>1279</td>\n",
       "      <td>588</td>\n",
       "      <td>-3.215683</td>\n",
       "      <td>1.078399</td>\n",
       "      <td>-2.137285</td>\n",
       "      <td>-6.158856</td>\n",
       "      <td>4.901168</td>\n",
       "      <td>...</td>\n",
       "      <td>-4.040157</td>\n",
       "      <td>1.885618</td>\n",
       "      <td>-2.154538</td>\n",
       "      <td>0.178167</td>\n",
       "      <td>0.178167</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-4.577678</td>\n",
       "      <td>1.543282</td>\n",
       "      <td>-3.034396</td>\n",
       "      <td>-0.268013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Precious Achiuwa</td>\n",
       "      <td>achiupr01</td>\n",
       "      <td>2021</td>\n",
       "      <td>1581</td>\n",
       "      <td>749</td>\n",
       "      <td>-4.122966</td>\n",
       "      <td>1.359278</td>\n",
       "      <td>-2.763688</td>\n",
       "      <td>-4.050779</td>\n",
       "      <td>-0.919712</td>\n",
       "      <td>...</td>\n",
       "      <td>-4.347596</td>\n",
       "      <td>0.954821</td>\n",
       "      <td>-3.392775</td>\n",
       "      <td>-0.246055</td>\n",
       "      <td>-0.246776</td>\n",
       "      <td>0.000721</td>\n",
       "      <td>-3.817713</td>\n",
       "      <td>0.474828</td>\n",
       "      <td>-3.342885</td>\n",
       "      <td>0.329157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Precious Achiuwa</td>\n",
       "      <td>achiupr01</td>\n",
       "      <td>2022</td>\n",
       "      <td>3802</td>\n",
       "      <td>1892</td>\n",
       "      <td>-2.521510</td>\n",
       "      <td>1.763502</td>\n",
       "      <td>-0.758008</td>\n",
       "      <td>-1.687893</td>\n",
       "      <td>3.103441</td>\n",
       "      <td>...</td>\n",
       "      <td>-2.517372</td>\n",
       "      <td>2.144151</td>\n",
       "      <td>-0.373221</td>\n",
       "      <td>2.262658</td>\n",
       "      <td>2.309611</td>\n",
       "      <td>-0.046953</td>\n",
       "      <td>-2.483956</td>\n",
       "      <td>2.024360</td>\n",
       "      <td>-0.459596</td>\n",
       "      <td>-0.728609</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 21 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        player_name  player_id  season  poss    mp  raptor_box_offense  \\\n",
       "0      Alex Abrines  abrinal01    2017  2387  1135            0.745505   \n",
       "1      Alex Abrines  abrinal01    2018  2546  1244            0.317549   \n",
       "2      Alex Abrines  abrinal01    2019  1279   588           -3.215683   \n",
       "3  Precious Achiuwa  achiupr01    2021  1581   749           -4.122966   \n",
       "4  Precious Achiuwa  achiupr01    2022  3802  1892           -2.521510   \n",
       "\n",
       "   raptor_box_defense  raptor_box_total  raptor_onoff_offense  \\\n",
       "0           -0.372938          0.372567             -0.418553   \n",
       "1           -1.725325         -1.407776             -1.291727   \n",
       "2            1.078399         -2.137285             -6.158856   \n",
       "3            1.359278         -2.763688             -4.050779   \n",
       "4            1.763502         -0.758008             -1.687893   \n",
       "\n",
       "   raptor_onoff_defense  ...  raptor_offense  raptor_defense  raptor_total  \\\n",
       "0             -3.857011  ...        0.543421       -1.144832     -0.601411   \n",
       "1             -0.049694  ...       -0.020826       -1.502642     -1.523468   \n",
       "2              4.901168  ...       -4.040157        1.885618     -2.154538   \n",
       "3             -0.919712  ...       -4.347596        0.954821     -3.392775   \n",
       "4              3.103441  ...       -2.517372        2.144151     -0.373221   \n",
       "\n",
       "   war_total  war_reg_season  war_playoffs  predator_offense  \\\n",
       "0   1.249008        1.447708     -0.198700          0.077102   \n",
       "1   0.777304        0.465912      0.311392         -0.174621   \n",
       "2   0.178167        0.178167      0.000000         -4.577678   \n",
       "3  -0.246055       -0.246776      0.000721         -3.817713   \n",
       "4   2.262658        2.309611     -0.046953         -2.483956   \n",
       "\n",
       "   predator_defense  predator_total  pace_impact  \n",
       "0         -1.038677       -0.961575     0.326413  \n",
       "1         -1.112625       -1.287247    -0.456141  \n",
       "2          1.543282       -3.034396    -0.268013  \n",
       "3          0.474828       -3.342885     0.329157  \n",
       "4          2.024360       -0.459596    -0.728609  \n",
       "\n",
       "[5 rows x 21 columns]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "continental-franklin",
   "metadata": {},
   "source": [
    "**Data Overview**\n",
    "\n",
    "This dataset comes from FiveThirtyEight and contains different data from NBA players from 2014-2022.  It includes the players' names, players' ids, and the season year.  It also includes number of possessions played and minutes played which both indicate how much time the player was on the court that season.  Also, the data includes raptor stats for offense, defense, and total which shows how effective a player was on that side of the court.  The data also shows predator stats for offense, defense, and total which is a prediction of how effective the player was.  Also, WAR (wins above replacement) stats were shown in the data which show how many more wins that player got their team over the season compared to if a replacement level player was playing instead.  Lastly, pace impact stats were shown which state the overall impact a player had on their team.  The pace impact stat for each player was shown as if each player played 48 minutes which is the length of the whole game."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "infinite-instrument",
   "metadata": {},
   "source": [
    "# Methods and Results"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "recognized-positive",
   "metadata": {},
   "source": [
    "## First Research Question: Who is better offensively, defensively, and all around, LeBron James or Kevin Durant?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "graduate-palmer",
   "metadata": {},
   "source": [
    "### Methods"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "endless-variation",
   "metadata": {},
   "source": [
    "**For the LeBron James Data:**  \n",
    "I will first need to get the data to only show LeBron James' seasons from 2014-2022.  I will do this by setting player_name equivalent to LeBron James and call this data Lebron_df.  I will then use the raptor_offense data and take the mean of all of his seasons.  This will give me a good representation of how effective he has been on offense.  I will then use the raptor_defense data and take the mean of all of his seasons.  I will then use the raptor_total data and take the mean of all of his seasons.  Doing all of this will give numerical numbers that represent how good LeBron James is offensively, defensively, and all around.  This can be done for other players and these numbers can be compared to see who is more impactful.\n",
    "\n",
    "**For the Kevin Durant Data:**  \n",
    "I will first need to get the data to only show Kevin Durant's seasons from 2014-2022.  I will do this by setting player_name equivalent to Kevin Durant and call this data Durant_df.  I will then use the raptor_offense data and take the mean of all of his seasons.  This will give me a good representation of how effective he has been on offense.  I will then use the raptor_defense data and take the mean of all of his seasons.  I will then use the raptor_total data and take the mean of all of his seasons.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "portuguese-japan",
   "metadata": {},
   "source": [
    "### Results "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "372a5883-7746-4932-9353-489eed28878e",
   "metadata": {},
   "source": [
    "#### LeBron James Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "9e6b2020-4df8-4e45-8b00-fbc398964376",
   "metadata": {},
   "outputs": [],
   "source": [
    "Lebron_df = df[df.player_name==\"LeBron James\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b57dfb5b-f725-43d7-bfaa-76e7d86ec69f",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(5.958565647986926)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Lebron_df.raptor_offense.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "496218f8-6823-4570-b97f-bdf2461e3e06",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.3291714363332999)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Lebron_df.raptor_defense.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "247b1e93-df57-4b13-a22f-656e6740e715",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(6.2877370843202245)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Lebron_df.raptor_total.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f1ea090f-a39c-40ba-85a7-bb55f5216130",
   "metadata": {},
   "source": [
    "#### Kevin Durant Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c0a35626-5356-4b7b-8e2b-eb83cc42b8f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "Durant_df = df[df.player_name==\"Kevin Durant\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "08415fc5-0f02-4e13-906a-c9dee9f8118e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(5.66912563466798)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Durant_df.raptor_offense.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "f37fb84f-4861-4e14-b6dc-502c180dcb4b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.20101735750424538)"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Durant_df.raptor_defense.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "a60e7ec7-27fb-47df-ba2a-94a84c7926e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(5.870142992047225)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Durant_df.raptor_total.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05e10133-bfb8-4c85-82e0-4d118082eb53",
   "metadata": {},
   "source": [
    "#### Data Explained\n",
    "LeBron James is better on average, offensively, defensively, and all around than Kevin Durant is.  LeBron's raptor offense, defense, and total rating is higher than Durant's.  This does not account for individual seasons but uses the data from all seasons from 2014-2022.  I will graph LeBron James' and Kevin Durant's individual seasons below. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2564b4db-58dd-4886-b1e3-261f7ae1b357",
   "metadata": {},
   "source": [
    "#### LeBron James and Kevin Durant Graphed"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "79e1f833-833a-4a75-b41d-eeab580bf713",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'LeBron James vs Kevin Durant')"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 28100 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.scatterplot(data=Lebron_df,x=\"season\",y=\"raptor_total\")\n",
    "sns.scatterplot(data=Durant_df,x=\"season\",y=\"raptor_total\")\n",
    "plt.ylim([0,9])\n",
    "plt.legend(labels=[\"LeBron James\",\"Kevin Durant\"])\n",
    "plt.title(\"LeBron James vs Kevin Durant\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db4cba31-c730-4111-8d78-0190d5ac86ec",
   "metadata": {},
   "source": [
    "#### Results from Graph\n",
    "This shows that Kevin Durant was better in 2014 and 2015 and LeBron James was better from 2016-2022.  This is the case because the data point for Kevin Durant was higher than LeBron James' for the seasons of 2014 and 2015 and LeBron James' data point was higher for the seasons of 2016-2022."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "collectible-puppy",
   "metadata": {},
   "source": [
    "## Second Research Question: Who is the best offensive player in the NBA?\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "demographic-future",
   "metadata": {},
   "source": [
    "## Methods"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64e47d9c-d4af-4c02-87af-d0087597d629",
   "metadata": {},
   "source": [
    "I will use the player_name, raptor_offense, and predator_offense for each player.  \n",
    "  \n",
    "**Initial Problem:**  \n",
    "I first completed this without excluding players who played less than 3000 minutes in a season and was finding that the data was showing me the best offensive NBA players were players who only played one game.  This was happening because a few players played great offensively in one game and never played again.  Obviously, those are not the best NBA players as they only played 1 or a few games in the NBA.\n",
    "\n",
    "**How I fixed this:**  \n",
    "I fixed this by removing all NBA players who played less than 3000 minutes throughout the 82 game season.  This only allowed the players who were good enough to play many minutes for their teams throughout the season.  This means that these were some of the best NBA players.  There are 48 minutes in an NBA game so I chose 3000 minutes since 3000/48 = 62.5 and that is about three quarters of the NBA season.\n",
    "\n",
    "**What I did:**  \n",
    "I first removed all players who played less than 3000 minutes.  I then grouped the data by the players' names as I called these the eligible players.  I then took all of the offensive stats in this dataset which were the raptor offense and predator offense data and took the averages of them which I called the offense stats.  I then added all of the offense stats together and sorted them by highest to lowest number.  The higher the number correlates with the better the offensive player which gives us a list ranking the best to worst offensive players that have all played over 3000 minutes.  I then turned the data back into a data frame, renamed the number column to be offense_stat and showed the new data frame containing a player’s name and the offensive value associated."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "e40a1730-6c77-425c-81b2-55f2bcd7d5d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>offense_stat</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>player_name</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Stephen Curry</th>\n",
       "      <td>17.720458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chris Paul</th>\n",
       "      <td>17.330227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>James Harden</th>\n",
       "      <td>15.526875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Isaiah Thomas</th>\n",
       "      <td>14.996093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LeBron James</th>\n",
       "      <td>12.947326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kevin Durant</th>\n",
       "      <td>12.235575</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Russell Westbrook</th>\n",
       "      <td>11.888737</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kyrie Irving</th>\n",
       "      <td>11.735169</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nikola Jokic</th>\n",
       "      <td>10.950040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Damian Lillard</th>\n",
       "      <td>10.012836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kyle Lowry</th>\n",
       "      <td>9.180744</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Karl-Anthony Towns</th>\n",
       "      <td>8.111974</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bradley Beal</th>\n",
       "      <td>7.866275</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jimmy Butler</th>\n",
       "      <td>7.821279</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Paul George</th>\n",
       "      <td>6.961966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Devin Booker</th>\n",
       "      <td>6.766783</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kemba Walker</th>\n",
       "      <td>6.752003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kevin Love</th>\n",
       "      <td>6.741710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>JR Smith</th>\n",
       "      <td>6.593562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Blake Griffin</th>\n",
       "      <td>6.389779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Giannis Antetokounmpo</th>\n",
       "      <td>6.112044</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>John Wall</th>\n",
       "      <td>5.753245</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Khris Middleton</th>\n",
       "      <td>5.306315</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CJ McCollum</th>\n",
       "      <td>5.276419</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jalen Brunson</th>\n",
       "      <td>5.237223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Klay Thompson</th>\n",
       "      <td>4.973756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jrue Holiday</th>\n",
       "      <td>4.947378</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Draymond Green</th>\n",
       "      <td>4.784848</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wesley Matthews</th>\n",
       "      <td>4.769245</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chandler Parsons</th>\n",
       "      <td>4.669383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DeAndre Jordan</th>\n",
       "      <td>4.652438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DeMar DeRozan</th>\n",
       "      <td>4.455351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nicolas Batum</th>\n",
       "      <td>4.372284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jayson Tatum</th>\n",
       "      <td>4.184372</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Otto Porter Jr.</th>\n",
       "      <td>4.088359</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Anthony Davis</th>\n",
       "      <td>4.076098</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jaylen Brown</th>\n",
       "      <td>4.026351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Joe Johnson</th>\n",
       "      <td>3.184046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mikal Bridges</th>\n",
       "      <td>3.180401</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Donovan Mitchell</th>\n",
       "      <td>2.917105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marcus Smart</th>\n",
       "      <td>2.869965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pascal Siakam</th>\n",
       "      <td>2.734799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Monta Ellis</th>\n",
       "      <td>2.503306</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tyrese Maxey</th>\n",
       "      <td>2.304135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ben Simmons</th>\n",
       "      <td>2.176836</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Joakim Noah</th>\n",
       "      <td>2.092434</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dorian Finney-Smith</th>\n",
       "      <td>2.053527</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Paul Millsap</th>\n",
       "      <td>1.773395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Trevor Ariza</th>\n",
       "      <td>1.711537</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chris Bosh</th>\n",
       "      <td>1.506055</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tobias Harris</th>\n",
       "      <td>1.468812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>David West</th>\n",
       "      <td>0.994692</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Andrew Wiggins</th>\n",
       "      <td>0.938364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bam Adebayo</th>\n",
       "      <td>0.618696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Serge Ibaka</th>\n",
       "      <td>0.557475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marc Gasol</th>\n",
       "      <td>0.541082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lance Stephenson</th>\n",
       "      <td>-0.108353</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marcin Gortat</th>\n",
       "      <td>-0.148795</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Hill</th>\n",
       "      <td>-0.353735</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Tucker</th>\n",
       "      <td>-1.726914</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       offense_stat\n",
       "player_name                        \n",
       "Stephen Curry             17.720458\n",
       "Chris Paul                17.330227\n",
       "James Harden              15.526875\n",
       "Isaiah Thomas             14.996093\n",
       "LeBron James              12.947326\n",
       "Kevin Durant              12.235575\n",
       "Russell Westbrook         11.888737\n",
       "Kyrie Irving              11.735169\n",
       "Nikola Jokic              10.950040\n",
       "Damian Lillard            10.012836\n",
       "Kyle Lowry                 9.180744\n",
       "Karl-Anthony Towns         8.111974\n",
       "Bradley Beal               7.866275\n",
       "Jimmy Butler               7.821279\n",
       "Paul George                6.961966\n",
       "Devin Booker               6.766783\n",
       "Kemba Walker               6.752003\n",
       "Kevin Love                 6.741710\n",
       "JR Smith                   6.593562\n",
       "Blake Griffin              6.389779\n",
       "Giannis Antetokounmpo      6.112044\n",
       "John Wall                  5.753245\n",
       "Khris Middleton            5.306315\n",
       "CJ McCollum                5.276419\n",
       "Jalen Brunson              5.237223\n",
       "Klay Thompson              4.973756\n",
       "Jrue Holiday               4.947378\n",
       "Draymond Green             4.784848\n",
       "Wesley Matthews            4.769245\n",
       "Chandler Parsons           4.669383\n",
       "DeAndre Jordan             4.652438\n",
       "DeMar DeRozan              4.455351\n",
       "Nicolas Batum              4.372284\n",
       "Jayson Tatum               4.184372\n",
       "Otto Porter Jr.            4.088359\n",
       "Anthony Davis              4.076098\n",
       "Jaylen Brown               4.026351\n",
       "Joe Johnson                3.184046\n",
       "Mikal Bridges              3.180401\n",
       "Donovan Mitchell           2.917105\n",
       "Marcus Smart               2.869965\n",
       "Pascal Siakam              2.734799\n",
       "Monta Ellis                2.503306\n",
       "Tyrese Maxey               2.304135\n",
       "Ben Simmons                2.176836\n",
       "Joakim Noah                2.092434\n",
       "Dorian Finney-Smith        2.053527\n",
       "Paul Millsap               1.773395\n",
       "Trevor Ariza               1.711537\n",
       "Chris Bosh                 1.506055\n",
       "Tobias Harris              1.468812\n",
       "David West                 0.994692\n",
       "Andrew Wiggins             0.938364\n",
       "Bam Adebayo                0.618696\n",
       "Serge Ibaka                0.557475\n",
       "Marc Gasol                 0.541082\n",
       "Lance Stephenson          -0.108353\n",
       "Marcin Gortat             -0.148795\n",
       "George Hill               -0.353735\n",
       "PJ Tucker                 -1.726914"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "players_over_3000 = df[df.mp>3000]\n",
    "eligible_players = players_over_3000.groupby(\"player_name\")\n",
    "offense_stats= eligible_players[[\"raptor_offense\",\"predator_offense\"]].mean()\n",
    "off_stat = offense_stats.sum(axis=1).sort_values(ascending=False)\n",
    "df_offense = pd.DataFrame(off_stat)\n",
    "df_offense.columns = [\"offense_stat\"]\n",
    "df_offense"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "8ea17bc0-35b9-4378-a35d-90f9cfd71064",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 42716 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.title(\"Top 5 Offensive Players and their Offensive Stat\")\n",
    "off_plot = sns.barplot(data=df_offense.head(), x=\"player_name\",y=\"offense_stat\",errorbar=None)\n",
    "plt.xticks(df_offense.head().index,rotation=45)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c60d07cf-bc4a-4151-bf70-7724cca89628",
   "metadata": {},
   "source": [
    "### Results\n",
    "I found that the best offensive player is Stephen Curry.  This makes sense as he is known as one of the best offensive players in the NBA and has been for years.  The next best offensive players are Chris Paul, James Harden, Isaiah Thomas, and LeBron James.  These are all guards, and LeBron James who has pretty much played every position in his career that are best on offense so this also makes sense.  I think that using the data points of raptor offense and predator offense were useful as it outputted a list of some of the best offensive players from 2014-2022."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9abb60c3-4aa0-45cf-bf6f-dbc2302ed7ea",
   "metadata": {},
   "source": [
    "#### Results from Graph\n",
    "This graph shows the difference between Stephen Curry, Chris Paul, and everyone else.  This shows the top 5 offensive players in the NBA from 2014-2022.  The offense_stat is the value of raptor_offense and predator_offense stats added together.  It is interesting to note that the majority of the best offensive players play point guard or shooting guard."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "702dbab9-27e7-4214-9639-ab2391a15bb6",
   "metadata": {},
   "source": [
    "## Third Research Question: Who is the best defensive player in the NBA?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ade012cc-5381-4dee-8fde-d66de63fcbc2",
   "metadata": {},
   "source": [
    "## Methods"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7036e91-71f5-415b-8752-460b28529d25",
   "metadata": {},
   "source": [
    "**What I did:**  \n",
    "This is very similar to the best offensive stats.  I only allowed players with 3000 minutes played which is the same pool of players that I included in seeing who the best offensive player was by making the players_over_3000 dataframe.  This time I looked at the data for raptor defense and predator defense.  I took the average of these two data points and added the number together.  This gives a good representation of how effective a player is on defense.  These are good data values to see who the best defensive players are."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "5aca0be4-035f-4de2-a955-b9584221eccd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>defense_stat</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>player_name</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Draymond Green</th>\n",
       "      <td>10.787943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Joakim Noah</th>\n",
       "      <td>9.358453</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Anthony Davis</th>\n",
       "      <td>7.895150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marc Gasol</th>\n",
       "      <td>6.534351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Paul George</th>\n",
       "      <td>6.408697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Paul Millsap</th>\n",
       "      <td>5.699113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Hill</th>\n",
       "      <td>5.241234</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Giannis Antetokounmpo</th>\n",
       "      <td>4.803693</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ Tucker</th>\n",
       "      <td>4.780241</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Serge Ibaka</th>\n",
       "      <td>4.703840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marcin Gortat</th>\n",
       "      <td>4.511971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jrue Holiday</th>\n",
       "      <td>4.421153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chris Paul</th>\n",
       "      <td>4.249789</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nikola Jokic</th>\n",
       "      <td>4.021482</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Marcus Smart</th>\n",
       "      <td>3.850867</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bam Adebayo</th>\n",
       "      <td>3.707044</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jimmy Butler</th>\n",
       "      <td>3.183364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DeAndre Jordan</th>\n",
       "      <td>3.154674</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kyle Lowry</th>\n",
       "      <td>3.141026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Otto Porter Jr.</th>\n",
       "      <td>2.968337</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pascal Siakam</th>\n",
       "      <td>2.750881</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Mikal Bridges</th>\n",
       "      <td>2.670235</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>David West</th>\n",
       "      <td>2.666690</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stephen Curry</th>\n",
       "      <td>2.582205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Donovan Mitchell</th>\n",
       "      <td>2.433277</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kevin Love</th>\n",
       "      <td>2.424493</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jaylen Brown</th>\n",
       "      <td>2.380194</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jayson Tatum</th>\n",
       "      <td>2.100925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dorian Finney-Smith</th>\n",
       "      <td>2.022662</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chris Bosh</th>\n",
       "      <td>1.673919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Blake Griffin</th>\n",
       "      <td>1.627615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Trevor Ariza</th>\n",
       "      <td>1.546710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kemba Walker</th>\n",
       "      <td>1.342204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Andrew Wiggins</th>\n",
       "      <td>1.244490</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Nicolas Batum</th>\n",
       "      <td>0.968720</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>James Harden</th>\n",
       "      <td>0.769140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Klay Thompson</th>\n",
       "      <td>0.543766</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Russell Westbrook</th>\n",
       "      <td>0.523426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Ben Simmons</th>\n",
       "      <td>0.456007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LeBron James</th>\n",
       "      <td>0.354197</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wesley Matthews</th>\n",
       "      <td>0.299899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CJ McCollum</th>\n",
       "      <td>-0.060706</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bradley Beal</th>\n",
       "      <td>-0.200945</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Khris Middleton</th>\n",
       "      <td>-0.477710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jalen Brunson</th>\n",
       "      <td>-0.508995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>John Wall</th>\n",
       "      <td>-0.695989</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Chandler Parsons</th>\n",
       "      <td>-0.873292</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kevin Durant</th>\n",
       "      <td>-0.913675</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Devin Booker</th>\n",
       "      <td>-0.916546</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Lance Stephenson</th>\n",
       "      <td>-1.036529</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Monta Ellis</th>\n",
       "      <td>-1.169090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tobias Harris</th>\n",
       "      <td>-1.576114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Karl-Anthony Towns</th>\n",
       "      <td>-1.776151</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Damian Lillard</th>\n",
       "      <td>-2.258608</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tyrese Maxey</th>\n",
       "      <td>-2.419741</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>JR Smith</th>\n",
       "      <td>-2.516657</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Kyrie Irving</th>\n",
       "      <td>-3.997132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DeMar DeRozan</th>\n",
       "      <td>-4.334230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Joe Johnson</th>\n",
       "      <td>-4.882167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Isaiah Thomas</th>\n",
       "      <td>-6.412895</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       defense_stat\n",
       "player_name                        \n",
       "Draymond Green            10.787943\n",
       "Joakim Noah                9.358453\n",
       "Anthony Davis              7.895150\n",
       "Marc Gasol                 6.534351\n",
       "Paul George                6.408697\n",
       "Paul Millsap               5.699113\n",
       "George Hill                5.241234\n",
       "Giannis Antetokounmpo      4.803693\n",
       "PJ Tucker                  4.780241\n",
       "Serge Ibaka                4.703840\n",
       "Marcin Gortat              4.511971\n",
       "Jrue Holiday               4.421153\n",
       "Chris Paul                 4.249789\n",
       "Nikola Jokic               4.021482\n",
       "Marcus Smart               3.850867\n",
       "Bam Adebayo                3.707044\n",
       "Jimmy Butler               3.183364\n",
       "DeAndre Jordan             3.154674\n",
       "Kyle Lowry                 3.141026\n",
       "Otto Porter Jr.            2.968337\n",
       "Pascal Siakam              2.750881\n",
       "Mikal Bridges              2.670235\n",
       "David West                 2.666690\n",
       "Stephen Curry              2.582205\n",
       "Donovan Mitchell           2.433277\n",
       "Kevin Love                 2.424493\n",
       "Jaylen Brown               2.380194\n",
       "Jayson Tatum               2.100925\n",
       "Dorian Finney-Smith        2.022662\n",
       "Chris Bosh                 1.673919\n",
       "Blake Griffin              1.627615\n",
       "Trevor Ariza               1.546710\n",
       "Kemba Walker               1.342204\n",
       "Andrew Wiggins             1.244490\n",
       "Nicolas Batum              0.968720\n",
       "James Harden               0.769140\n",
       "Klay Thompson              0.543766\n",
       "Russell Westbrook          0.523426\n",
       "Ben Simmons                0.456007\n",
       "LeBron James               0.354197\n",
       "Wesley Matthews            0.299899\n",
       "CJ McCollum               -0.060706\n",
       "Bradley Beal              -0.200945\n",
       "Khris Middleton           -0.477710\n",
       "Jalen Brunson             -0.508995\n",
       "John Wall                 -0.695989\n",
       "Chandler Parsons          -0.873292\n",
       "Kevin Durant              -0.913675\n",
       "Devin Booker              -0.916546\n",
       "Lance Stephenson          -1.036529\n",
       "Monta Ellis               -1.169090\n",
       "Tobias Harris             -1.576114\n",
       "Karl-Anthony Towns        -1.776151\n",
       "Damian Lillard            -2.258608\n",
       "Tyrese Maxey              -2.419741\n",
       "JR Smith                  -2.516657\n",
       "Kyrie Irving              -3.997132\n",
       "DeMar DeRozan             -4.334230\n",
       "Joe Johnson               -4.882167\n",
       "Isaiah Thomas             -6.412895"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "players_over_3000 = df[df.mp>3000]\n",
    "eligible_players = players_over_3000.groupby(\"player_name\")\n",
    "defense_stats= eligible_players[[\"raptor_defense\",\"predator_defense\"]].mean()\n",
    "def_stat = defense_stats.sum(axis=1).sort_values(ascending=False)\n",
    "df_defense = pd.DataFrame(def_stat)\n",
    "df_defense.columns = [\"defense_stat\"]\n",
    "df_defense"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "afe7a597-ce41-45f5-89f1-b82064088890",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 40612 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.title(\"Top 5 Defensive Players and their Defensive Stat\")\n",
    "def_plot = sns.barplot(data=df_defense.head(), x=\"player_name\",y=\"defense_stat\",errorbar=None)\n",
    "plt.xticks(df_defense.head().index,rotation=45)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8793880e-f0cb-4304-bdad-d54f25a5b426",
   "metadata": {},
   "source": [
    "### Results\n",
    "I found that the best defensive player from 2014-2022 was Draymond Green.  This makes sense as he has won the Defensive Player Of The Year award and is known primarily for his defense.  He is known as one of the best defensive players in the league.  I am not surprised to see Draymond Green be the number one ranked defensive player.  The three next best defensive players are Anthony Davis, Joakim Noah, and Paul George.  These players are also known for their defense, so it makes sense that they are rated so highly.  It is interesting to note that 4 of the top 5 players are Power Forwards or Centers which also shows that this could lead to research on whether Power Forwards and Centers generally play the best defense."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "90e25901-eb61-42cc-9d11-742ba515bfd9",
   "metadata": {},
   "source": [
    "#### Results from Graph\n",
    "This graph shows the difference between Draymond Green and everyone else.  This shows the top 5 defensive players in the NBA from 2014-2022.  The defense_stat is the value of raptor_defense and predator_defense stats added together."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "infectious-symbol",
   "metadata": {},
   "source": [
    "# Discussion"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "furnished-camping",
   "metadata": {
    "code_folding": []
   },
   "source": [
    "## Considerations"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27b18f33-f5fc-4eda-a0d2-1be37c5b6d76",
   "metadata": {},
   "source": [
    "My results give an accurate depiction of showing who is better between Kevin Durant and LeBron James and who the best offensive and defensive players in the NBA are.  Determining who is better between Kevin Durant and LeBron James is accurate as I used offensive, defensive, and overall impact data for both players and compared them.  I decided to add all of the values together as I thought that would accurately determine who has been better.  A person could use other data not given in the data set as there could be other metrics that better capture who the better player is.  In regard to who the best offensive and defensive players are in the NBA, the results are accurate as I used 2 different data points for offense and 2 data points for defense.  This makes the data give the overall best offensive and defensive player.  Also, the players given at the top of the best offensive and defensive players lists are known for their skill on that side of the court which further suggests that the data is accurate.\n",
    "\n",
    "Some limitations of the data set are that there are other statistics that were not factored in the data.  Also, this compares players only by specific data points and does not factor in how they effect their teammates which is very important in determining how good a player is.  This includes the leadership a player brings to their team and how that elevates their teammates.  Another limitation is that I used 3000 or more minutes played as a qualification to be considered.  There could be good players that played 2999 minutes and were not counted.  The other limitation is that the data goes from 2014-2022.  This is not recent enough as we are in 2025 and does not include data from the previous 2-3 seasons.  Also, it is necessary to note that it does not include data from before 2014.  This is a problem when discussing LeBron James and Kevin Durant as they both played prior to 2014.\n",
    "\n",
    "There are no known biases in the data as it does not factor in personal opinions of players."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "beneficial-invasion",
   "metadata": {},
   "source": [
    "## Summary"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2c65367-4696-4cb5-81c3-faaa9cfc7b0d",
   "metadata": {},
   "source": [
    "I learned that my media consumption has led me to decide to use this data set.  I see a lot of NBA media so I was interested in using NBA data for this project.\n",
    "\n",
    "When reflecting on this project, this data could definitely be used by NBA teams to decide which players they should try to acquire.  In the off-season teams are allowed to sign free agents and trade for players.  This data could allow teams to realize who the better player is and acquire that player.\n",
    "\n",
    "I learned that LeBron James is better than Kevin Durant both offensively and defensively.  This can make sense although it is pretty surprising that LeBron James was better on offense.  Stephen Curry, Chris Paul, and James Harden were found to be the best players offensively which completely makes sense as they have been some of the best offensive players from 2014-2022.  Draymond Green, Joakim Noah, and Anthony Davis were found to be the best players defensively which completely makes sense as Draymond Green and Joakim Noah were some of the best defenders from 2014-2022.  Overall, I would say that the results make sense to me showing that the data was accurate.\n",
    "\n",
    "The most surprising thing was that LeBron James was better offensively than Kevin Durant.  I assumed he would be better defensively but I was not expecting him to be better on offense.  Kevin Durant is known as one of the best overall scorers and shooters so I definitely did not expect LeBron James to be better on offense.  I was also surprised that Stephen Curry was rated so highly defensively.  He is not thought of as one of the best defenders so this was interesting to see.\n",
    "\n",
    "This project will impact me when I am watching basketball in the future.  I will watch Kevin Durant and LeBron James and see for myself who is better at offense.  I will also watch to see how the best offensive and defensive players have changed since 2022."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41ca88fe-6262-474c-af0c-1f191ff4790a",
   "metadata": {},
   "source": [
    "## Final Poster"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7b9c078-dd64-40ae-b1e5-496afa39fd45",
   "metadata": {},
   "source": [
    "The final poster is attached as the James Berent Flyer.pdf"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44248208-44a9-47f5-85e9-c61d4b06c9a0",
   "metadata": {},
   "source": [
    "# Add Data Structures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "398f3b13-0813-4052-a43f-68903048ed39",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_json": true,
   "text_representation": {
    "extension": ".Rmd",
    "format_name": "rmarkdown",
    "format_version": "1.2",
    "jupytext_version": "1.9.1"
   }
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
