Git Product home page Git Product logo

usports-basketball's Introduction

๐Ÿ€ usports-basketball

Ruff PyPI Latest Release License Downloads Package Status

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_teams_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_teams_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_teams_stats, usports_player_stats

# Fetching and processing men's team statistics
men_team_stats_df = usport_teams_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_teams_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.

usports-basketball's People

Contributors

ojadeyemi avatar

Stargazers

 avatar

Watchers

Kostas Georgiou avatar  avatar

usports-basketball's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.