text_html_output_1.png
from plotly.offline import iplot, init_notebook_mode

import numpy as np

import pandas as pd

import pandas as pd
import numpy as np
import plotly.plotly as py
from plotly.graph_objs import *
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()
data = pd.read_csv('../input/shot_logs.csv')
playerIDList = list(data['player_id'].unique())
defenderIDList = list(data['CLOSEST_DEFENDER_PLAYER_ID'].unique())
attackerIDList = list(data['player_id'].unique())
playerData = pd.DataFrame(index=playerIDList, columns=['player', 'made', 'missed', 'fg_percentage', 'made_against', 'missed_against', 'fg_percentage_against'])
for defenderID in defenderIDList:
    name = data[data['CLOSEST_DEFENDER_PLAYER_ID'] == defenderID]['CLOSEST_DEFENDER'].iloc[0]
    made = np.sum(data[data['CLOSEST_DEFENDER_PLAYER_ID'] == defenderID]['SHOT_RESULT'] == 'made')
    missed = np.sum(data[data['CLOSEST_DEFENDER_PLAYER_ID'] == defenderID]['SHOT_RESULT'] == 'missed')
    percentage = made / (made + missed)
    playerData.at[defenderID, 'player'] = name
    playerData.at[defenderID, 'made_against'] = made
    playerData.at[defenderID, 'missed_against'] = missed
    playerData.at[defenderID, 'fg_percentage_against'] = percentage
for attackerID in attackerIDList:
    made = np.sum(data[data['player_id'] == attackerID]['SHOT_RESULT'] == 'made')
    missed = np.sum(data[data['player_id'] == attackerID]['SHOT_RESULT'] == 'missed')
    percentage = made / (made + missed)
    playerData.at[attackerID, 'made'] = made
    playerData.at[attackerID, 'missed'] = missed
    playerData.at[attackerID, 'fg_percentage'] = percentage
newPlayerData = playerData.sort_values('fg_percentage_against')
newPlayerData2 = newPlayerData.drop(newPlayerData[newPlayerData.missed_against < 200].index)

ESPNRankTop30 = ['James, LeBron', 'Paul, Chris', 'Davis, Anthony', 'Westbrook, Russell', 'Griffin, Blake', 'Curry, Stephen', 'Love, Kevin', 'Durant, Kevin', 'Harden, James', 'Howard, Dwight', 'Anthony, Carmelo', 'Noah, Joakim', 'Aldridge, LaMarcus', 'Gasol, Marc', 'Parker, Tony', 'Lillard, Damian', 'Nowitzki, Dirk', 'Wall, John', 'Cousins, DeMarcus', 'Bosh, Chris', 'Duncan, Tim', 'Jefferson, Al', 'Irving, Kyrie', 'Leonard, Kawhi', 'Ibaka, Serge', 'Horford, Al', 'Dragic, Goran', 'Rose, Derrick', 'Lowry, Kyle', 'Drummond, Andre']
newPlayerData3 = newPlayerData[newPlayerData['player'].isin(ESPNRankTop30)]
newPlayerData3 = newPlayerData3.sort_values('player')
newPlayerData3['ranking'] = 0
for i in range(len(ESPNRankTop30)):
    newPlayerData3.loc[newPlayerData3['player'] == ESPNRankTop30[i], 'ranking'] = str(i + 1)

newPlayerData3