While spending hours attempting to figure out ways to import stats to an Excel file I came across a version of this script that I've attempted to use in Python. When executing I get the following error below the second csv_output portion of the script:
KeyError: 0
I'm just beginning to learn the nuances of Python and can't really figure out what I'm doing wrong here.
I'm currently using Python 3.6 and Windows 10. Any help would be greatly appreciated.
import requests
import csv
url = "http://stats.nba.com/stats/leagueLeaders?
LeagueID=00&PerMode=PerGame&Scope=S&Season=2017-
18&SeasonType=Regular+Season&StatCategory=PTS"
data = requests.get(url, timeout=5)
entries = data.json()
with open('output.csv', 'w') as f_output:
csv_output = csv.writer(f_output)
csv_output.writerow(entries['resultSet'][0]['headers'])
csv_output.writerows(entries['resultSet'][0]['rowSet'])