nba_api | An API Client package to access the APIs for NBA.com | REST library
kandi X-RAY | nba_api Summary
kandi X-RAY | nba_api Summary
nba_api is an API Client for www.nba.com. This package is meant to make the API Endpoints more accessible and to provide extensive documentation. The APIs on www.nba.com are largely undocumented and change frequently. Please feel free to contribute and have an open discussion regarding improvements and additional APIs to be mapped.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Analyze endpoint_list and save it to file
- Analyze an endpoint
- Removes invalid parameters from the given endpoint
- Test for invalid parameters
- Generate all endpoint documentation
- Get the python variable name
- Get the documentation for an endpoint
- Builds a URL query string from a list of parameters
- Sends the request
- Get the API request
- Sends an API request
- Find team name by ID
- Performs a GET request
- Perform a GET request
- Send a request to Nba
- Sends a request
- Find player by id
- Find a team by its abbreviation
- Make a request to the API
- Performs a GET request
- Get the API request
- Request API response
- Get API request
- Make a GET request
- Sends an API request
- Request the API
nba_api Key Features
nba_api Examples and Code Snippets
os.makedirs(PATH, exist_ok=True)
import os
import urllib.request
import json
import logging
BASE_URL = 'https://cdn.nba.com/static/json/liveData/playbyplay/playbyplay_'
PATH = os.path.join(os.getcwd(), 'nba-matche
# source datafrome
year = '2020'
df = pd.read_excel('https://www.sportsbookreviewsonline.com/scoresoddsarchives/mlb/mlb%20odds%202011.xlsx')
df = df.dropna(how="all").copy()
df["Date"] = df["Date"].astype(int) # To handle excel float typ
# get teams from the reg season 2021-22
teamfinder = commonteamroster.CommonTeamRoster(season='2021-22',
team_id='1610612738',
league_id_nullable='
game_ids = games['GAME_ID'].unique().tolist()
for game_id in game_ids:
player_stats_data = boxscoreadvancedv2.BoxScoreAdvancedV2(game_id=game_id, headers=headers, timeout=100)
# Use the stats...
response = shotchartdetail.ShotChartDetail(
team_id=0,
player_id=0,
season_nullable='2001-02',
context_measure_simple = 'FGA', #<-- Default is 'PTS' and will only return made shots, but we want all shot attempts
seas
df = pd.DataFrame(rows)
try:
df.columns = headers
except:
pass
{
'CommonPlayerInfo': [ ... ],
'PlayerHeadlineStats': [ ... ],
'AvailableSeasons': [ ...]
}
player_info = player_info.get('CommonPlayerInfo')[0]
Community Discussions
Trending Discussions on nba_api
QUESTION
I am trying to scrape the data from NBA stats, specifically the team's boxscore. I am looking for the nba_api endpoint for this page so that i can scrape the data.
How can I find the endpoint?
...ANSWER
Answered 2022-Mar-20 at 15:59I'm not a huge sports fan, but this seems like it: A free NBA Boxscore API You could attempt to isolate the CSS, JS and HTML segments from the site.
It is in the source of a div.
QUESTION
I'm currently attempting to grab the latest team rosters from the NBA using the commonteamroster endpoint, but it seems like whatever season_id I enter, it only returns the 2020 rosters.
The roster I am looking at grabbing can be found here: https://www.nba.com/stats/team/1610612738/?Season=2021-22
My code
...ANSWER
Answered 2021-Sep-19 at 08:06It works fine. Did you not look at the output from:
QUESTION
import pandas as pd
import requests
headers = {
'Connection': 'keep-alive',
'Accept': 'application/json, text/plain, */*',
'x-nba-stats-token': 'true',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
'x-nba-stats-origin': 'stats',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Referer': 'https://stats.nba.com/',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
}
from nba_api.stats.endpoints import leaguegamefinder
# get game logs from the reg season
gamefinder = leaguegamefinder.LeagueGameFinder(season_nullable='2020-21',
league_id_nullable='00',
season_type_nullable='Regular Season')
games = gamefinder.get_data_frames()[0]
# get a list of distinct game ids
game_id = games['GAME_ID'].unique().tolist()
player_stats_data = boxscoreadvancedv2.BoxScoreAdvancedV2(game_id=game_id, headers=headers, timeout=100)
stats_df = player_stats_data.get_data_frames()[0]
stats_df.head()
...ANSWER
Answered 2021-Sep-11 at 06:09Looking at the API documentation, it takes a single game id.
One approach could be to loop over the game ids you have:
QUESTION
I'm trying to create a program for class, and am struggling, it was somewhat working at one point, but I have a feeling I may have blacklisted myself, cause I'm getting a MaxRetryError when executing the code.
Max retries exceeded with url: /session/535f3b31b6b76ca10ea210f69675563e/url (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'
I was wondering if my code will work on someone else's machine haha :D
So the jist of my code is that the user will be asked a date in the format yyyy-mm-dd then uses that date to find all the box scores associated with the date.
This is the function giving me grief.
...ANSWER
Answered 2021-Apr-30 at 07:06There is an api. Just use the gameid and then you can parse the json however you wish. For example:
QUESTION
I want to get data from nba site to create shot chart. I get it from this site https://datavizardry.com/2020/01/28/nba-shot-charts-part-1/?fbclid=IwAR3BheHQkSAmCJRr_z7ux1ygbspLjLdrvTRjWAVHOrr2BPvVh7jsIos_e9w and my code looks like this:
...ANSWER
Answered 2021-Jan-08 at 13:46The package by default (likely its been updated since the article) is set to only return shots where a point was scored, so you need to change that parameter to not be points, but rather field goal attempts, since that will return made and missed shots:
QUESTION
Having an issue converting NBA-API object to a DataFrame. What I get is a list of the dataframe. How do I pull the DataFrame out the list or skip the list and create the DataFrame.
...ANSWER
Answered 2020-Nov-13 at 22:40This?
QUESTION
here is the mismatch error I keep getting. I'm inputting "202710".
...ANSWER
Answered 2020-Oct-05 at 14:49This is because your df
is empty for ID 202710
. Exception handling will resolve the issue here-
QUESTION
I recently have been trying to use the NBA API to pull shot chart data. I'll link the documentation for the specific function I'm using here.
I keep getting a traceback as follows:
...ANSWER
Answered 2020-Sep-29 at 13:11You are getting this because the filename
has no extension. Pandas will use the extension (like xlsx
or xls
) of the filename (if you're not giving it an ExcelWriter
) to understand the right lib to use for this format. Just try this with something like df.to_excel('filename.xlsx', index=False)
and see how goes.
QUESTION
In my code for an NBA simulation which allows the user to select 2 teams from the same or different seasons. If the user selects both teams from the 2019-20 season then the team 1 point array and opponent 1 point array is filled but the team 2 and opponent 2 arrays are empty. Every other combination of seasons and teams work e.g. team 1 from 2019-20 and team 2 from 2015-16. I'm pretty sure the issue is to do with the for loop in the if statement checking if the season2 is equal to 2019-20.
...ANSWER
Answered 2020-Sep-02 at 20:37After the first for
loop everything in the file has been read, so there's nothing left for the second loop to read. Starting a new for
loop doesn't reset the file back to the beginning. You need to seek back to the beginning of the file before trying to read it again.
QUESTION
Hello I'm trying to export a pandas dataframe in a csv file but I got no clue how to do it. And I got this error 'list' object has no attribute 'to_csv'
...ANSWER
Answered 2020-Aug-21 at 14:09You have a list of dataframes instead of the dataframe. You can either to save each one of them using .to_csv()
method or use pd.concat(player_results, axis=0)
to concatenate them and then save it.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install nba_api
requests
pandas (optional)
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page