seemethere / nba_py

Python client for NBA statistics located at stats.nba.com
BSD 3-Clause "New" or "Revised" License
1.05k stars 255 forks source link

Shot Chart for all players, all season #100

Open luzer opened 6 years ago

luzer commented 6 years ago

hi looking for an easy way to get all player's or team's charts, for a season or all seasons...

from nba_py import shotchart
from nba_py.player import get_player
import json
import pandas as pd
from nba_py.constants import TEAMS
from nba_py import team

pid = get_player('Kevin', 'Durant')
tid = TEAMS['SAC']['id']
team_details = team.TeamDetails(tid)

sc = shotchart.ShotChart(tid)

#print sc.json['resultSets']

# Grab the headers to be used as column headers for our DataFrame
headers = sc.json['resultSets'][0]['headers']
# Grab the shot chart data
shots = sc.json['resultSets'][0]['rowSet']

shot_df = pd.DataFrame(shots, columns=headers)
# View the head of the DataFrame and all its columns
shot_df.to_csv('shot_chart.csv',  encoding='utf-8')

with open('shot_chart.json', 'w') as outfile:
    json.dump(sc.json, outfile)
nharrisanalyst commented 6 years ago

Did this not work?