An NBA player props prediction tool using Python and nba_api to calculate averages and project stats.
This Python script fetches NBA player game logs using the nba_api library and calculates projected stats for points, rebounds, assists, and their combinations. Itβs ideal for NBA player props research, fantasy sports, or general analysis.
-
Player Name Search:
- Supports partial name searches (e.g., "Tatum" for Jayson Tatum).
- Filters results to show only active NBA players for cleaner results.
- Handles common names (e.g., "Brown") by limiting the search to manageable results.
-
Stat Projections:
- Calculates player averages for:
- Points (PTS)
- Rebounds (REB)
- Assists (AST)
- Combo Stats: P+R, P+A, R+A, P+R+A
- Based on the last N games (user-specified, default = 5).
- Calculates player averages for:
-
Data Export:
- Saves projected stats to a CSV file for easy analysis.
Ensure you have Python 3.7+ installed. Install the required libraries using pip:
pip install nba_api pandas
V2 Code
948a248
Here are todays changes
Features
Fetch and analyze game logs for specific players.
Compare player performance against a selected opponent team.
Calculate projected player stats based on recent games and matchup deltas.
Display team rankings for key stats (points, rebounds, assists, steals, blocks).
Save projected player stats as a CSV file for further analysis.
Requirements
Python 3.7 or higher
Dependencies:
nba_api
pandas
Install dependencies using:
bash
Copy code
pip install nba_api pandas
How to Use
Running the Tool
Run the script using Python:
bash
Copy code
python download_data.py
Follow the prompts:
Enter the player's name or last name.
Specify the number of recent games to analyze (default is 5).
Choose an opponent team for matchup analysis from the provided list.
Example Workflow
Enter Fox to analyze De'Aaron Fox.
Choose 11 for Los Angeles Lakers as the opponent team.
View the projected stats for De'Aaron Fox based on his recent games and the matchup against the Lakers.
Output
Player stats are displayed in the terminal.
Projected stats are saved in a CSV file named Player_Name_projected_stats.csv in the working directory.
Key Functions
Player Analysis
Fetch player stats using fetch_player_data_by_name(player_name, season).
Analyze weighted averages for points, rebounds, assists, steals, and blocks.
Opponent Team Analysis
Fetch opponent team game logs and calculate average stats for the last 5 games.
Compare team rankings for key metrics.
Matchup Analysis
Calculate deltas between a player's season averages and performance against the selected opponent team.
Adjust projected stats based on matchup deltas.
Limitations
Requires an active internet connection for API requests.
Large datasets may result in longer processing times.
Limited to analyzing regular season data for the specified season.
Development
Converting to Executable
To create an executable version:
Install pyinstaller:
bash
Copy code
pip install pyinstaller
Build the executable:
bash
Copy code
pyinstaller --onefile --console download_data.py
The generated executable will be in the dist folder.
Troubleshooting
If you encounter a "connection aborted" error, ensure your internet connection is stable.
For missing stats or errors in player or team data, verify the API is accessible.
Contributions
Feel free to contribute by submitting pull requests or reporting issues in the repository.