def getDivision(team, date): year = date.split('-')[0] seasonRecord = standings(int(year)) for divisions in seasonRecord: divisionTeams = list(divisions['Tm'].apply(nameFix)) if team in divisionTeams: break return divisionTeams
def main(): nl = standings()[3:] gs = [] for div in nl: div['g'] = div['W'].astype(int) + div['L'].astype(int) gs.append(div['g'].mean()) pace = sum(gs) / len(gs) / 162.0 * 1500 print('Pace for 1500 innings: {}'.format(pace)) root = tk.Tk(className='MyTkApp') root.withdraw() messagebox.showinfo('Inning Pace', str('Pace for 1500 innings: {}'.format(str(pace))))
def _set_team_list(year): """ Creates a list of dictionaries of the team containing data Params: year(int): year for which season data is wanted Returns: a list of dictionaries of teams that contains team name, record, logo url """ table = standings(year) team_list = [] for division in table: for ind in range(len(division)): team_name = division["Tm"][ind + 1] team_dict = { "title": team_name, "record": division["W"][ind + 1] + "-" + division["L"][ind + 1], "image": get_team_logo(team_name), "children": "" } team_list.append(team_dict) return team_list
""" team_batting_WAR_2019 = team_batting_WAR_2019.loc[ team_batting_WAR_2019['Team'] != '---'] print(team_batting_WAR_2019.sort_values('WAR', ascending=False).head(5)) """ Next we will work on merging two DataFrames. This is very common, and is important when you have info in two different places that you want to use together. In the below code, we have our WAR DataFrame and want to see how it correlates to team wins. Although, we do not have a team wins DataFrame. Luckily, pybaseball has a standings attribute we can pull the season standings from any year. So we will pull from 2019 and clean it up. The standings data is a list of DataFrames broken up by division. For our purpose we want to use it as one DataFrame so we are going to use a loop to append them all together, then we will have the Wins DataFrame which will show the standings for each individual team. """ standings = pyb.standings(2019) wins = pd.DataFrame() #we are using pd.concat to iteratively update our DataFrame for division_df in standings: wins = pd.concat([wins, division_df]) wins = wins.rename({'Tm': 'Team'}, axis=1) #print(wins) """ The problem with the above code, is when you are merging the two DataFrames, it won't know that the Los Angeles Dodgers, and Dodgers are the same, so we need to use str.split() in order to fix this. Although, we run into another problem with team names like the Blue Jays, and White/Red Sox. We use iloc to be able to fix this porition of the problem.
def __init__(self, year): super().__init__(pybaseball.standings())
@author: Max """ import pybaseball import numpy as np import pandas as pd from pybaseball import schedule_and_record from pybaseball import standings import requests from bs4 import BeautifulSoup cyear = 2018 pyear = 2017 p_records = schedule_and_record(pyear, 'BOS') standingsdata = standings(2016) # unique Teams from batting stats from pybaseball import team_batting bsTeams = team_batting(2010, cyear)['Team'].unique() #or #list(set(team_batting(2010, cyear)['Team'])) # unique Teams from standings from pybaseball import standings sTeams = pd.concat(standings(pyear))['Tm'].unique() import pandas as pd import requests from bs4 import BeautifulSoup
def get_size(year): val = standings(year) size = val[0].get('Name') return size.size
def get_data(year, div_id=0): league_data = standings(year)[div_id].values return league_data