Generation

generate functionSat, 07 Jan 2023

a bot that scrapes nba.com for all player stats. Stats should include points per game(ppg), assists per game(apg), rebounds per game(rpg), steals per game(spg).

import requests from bs4 import BeautifulSoup import pandas as pd import numpy as np def nba_stats(): url = "https://www.basketball-reference.com/leagues/NBA_2020_per_game.html" response = requests.get(url) soup = BeautifulSoup(response.content, "html.parser") table = soup.find("table", id="per_game_stats") stats = table.find("tbody") player_stats = [] for row in stats.findAll("tr"): player = row.find("th", {"data-stat": "player"}) ppg = row.find("td", {"data-stat": "pts_per_g"}) apg = row.find("td", {"data-stat": "ast_per_g"}) rpg = row.find("td", {"data-stat": "trb_per_g"}) spg = row.find("td", {"data-stat": "stl_per

Want to kickstart your project?Use the new AI Studio to create your code