A Python package for current U Sports basketball stats.
Project description
🏀 usports-basketball
usports-basketball is a Python package that fetches and analyzes current basketball stats from the U Sports website.
With two simple functions you can easily retrieve detailed data for either the men's or women's league.
usport_team_stats
: Fetch team stats.usport_players_stats
: Fetch player stats.
Each function returns a pandas DataFrame with the relevant statistics, allowing users to gather data for analysis and insights.
📥 Installation
You can install the package via pip:
pip install usports-basketball
🧩 Dependencies
This package relies on the following dependencies:
- pandas
- BeautifulSoup (bs4)
- requests
- pytest
- playwright
Installing Chromium for Playwright
After installing the package, you'll need to install Playwright's Chromium browser. Run the following command:
playwright install chromium
Functions
usport_team_stats
This function fetches and processes team statistics data, including standings, win-loss totals, shooting percentages, and other relevant team metrics for the current U Sports basketball season.
Parameters
arg
(str): The league for which you want to retrieve team statistics. Valid values are'men'
and'women'
or'm'
and'w'
(case-insensitive).season_option
(str, optional): The season type to fetch data for. Options are:'regular'
(default): Regular season statistics.'playoffs'
: Playoff season statistics.'championship'
: Championship season statistics.
Returns
DataFrame
: A pandas DataFrame containing the team statistics data.
usports_player_stats
This function fetches and processes player statistics data, including total games played, points scored, shooting percentages, rebounds, assists, turnovers, steals, blocks, and other individual player metrics for the current U Sports basketball season.
Parameters
arg
(str): The league for which you want to retrieve team statistics. Valid values are'men'
and'women'
or'm'
and'w'
(case-insensitive).season_option
(str, optional): The season type to fetch data for. Options are:'regular'
(default): Regular season statistics.'playoffs'
: Playoff season statistics.'championship'
: Championship season statistics.
Returns
DataFrame
: A pandas DataFrame containing the player statistics data.
Usage
-
Fetching current stats from the league
from usports_basketball import usport_team_stats, usports_player_stats
# Fetching and processing men's team statistics
men_team_stats_df = usport_team_stats('m')
# Fetching and processing men's player statistics
men_player_stats_df = usport_players_stats('m')
# Fetch statistics for women's playoff teams
women_team_stats_df = usport_team_stats('w', 'playoffs')
# Fetch statistics for women's players playing in U Sports championship Final 8
women_player_stats_df = usport_players_stats('w', 'championship')
-
Viewing Column Names
# Use these code snippets to see all column names in each DataFrame
# For the team statistics DataFrame
print("Column names in men's player statistics DataFrame:")
print(men_player_stats_df.columns.tolist())
# For the player statistics DataFrame
print("\nColumn names in men's player statistics DataFrame:")
print(men_player_stats_df.columns.tolist())
-
Exporting DataFrame to different files
# Export the to a CSV file using the `to_csv()` method
men_team_stats_df.to_csv('men_team_stats.csv', index=False) # Export without row index
#Export to a HTML table representation using to_html method
men_team_stats_df.to_html('table.html')
#Export to a JSON file using the to_json() method
men_team_stats_df.to_json('men_team_stats.json', orient='records') # Export in 'records' format
#Export to a SQLite database using the to_sql() method (requires SQLAlchemy)
from sqlalchemy import create_engine
engine = create_engine('sqlite:///usports_stats.db') #Export to SQLite database
women_team_stats_df.to_sql('team_stats', con=engine, index=False) # Export without row index
women_player_stats_df.to_sql('player_stats', con=engine, index=False) # Export without row index
Explore Pandas DataFrame documentation for instructions on manipulating data and performing data analysis.
Author
This package was developed by OJ Adeyemi.
Contributing
Contributions, bug reports, and feature requests are welcome! Please feel free to open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License. See the LICENSE file for details. for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file usports_basketball-2.0.2.tar.gz
.
File metadata
- Download URL: usports_basketball-2.0.2.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b94473193dff987c237ae708c143505722326815c375399759d1b5c7df32a397 |
|
MD5 | 1fea235d557307ed19e43cd468cd2769 |
|
BLAKE2b-256 | 47ab4cd979192cbe9e0c64a2498ba9a0d6a369bee8fe50ee40099088a3af264b |
Provenance
The following attestation bundles were made for usports_basketball-2.0.2.tar.gz
:
Publisher:
python-publish.yml
on ojadeyemi/usports-basketball
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
usports_basketball-2.0.2.tar.gz
- Subject digest:
b94473193dff987c237ae708c143505722326815c375399759d1b5c7df32a397
- Sigstore transparency entry: 151127809
- Sigstore integration time:
- Predicate type:
File details
Details for the file usports_basketball-2.0.2-py3-none-any.whl
.
File metadata
- Download URL: usports_basketball-2.0.2-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cc22dafaf849f0ac7d09f032c881d055272a436a67ef53926dbc8b7c965cc28 |
|
MD5 | 4e8630ccf7aea620d914933f5084e110 |
|
BLAKE2b-256 | 4c1334edea605bdec64926b668633ac60c22a13d88d7eae1d6d4cd6e7a92ef38 |
Provenance
The following attestation bundles were made for usports_basketball-2.0.2-py3-none-any.whl
:
Publisher:
python-publish.yml
on ojadeyemi/usports-basketball
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
usports_basketball-2.0.2-py3-none-any.whl
- Subject digest:
1cc22dafaf849f0ac7d09f032c881d055272a436a67ef53926dbc8b7c965cc28
- Sigstore transparency entry: 151127810
- Sigstore integration time:
- Predicate type: