Skip to content

Utilizing the MLB-StatsAPI I use a pandas dataframe to organize and collect the amount of runs for a team(s) organized by inning between the dates and export the dataframe to a xlsx.

Notifications You must be signed in to change notification settings

Vincent-Crescente/mlb-boxscore-analysis

Repository files navigation

I wanted to see the percentage of runs a team or teams
score in a certain inning compared to their total, giving you
the 'hot' innings of a team.

I used the MLB StatsAPI from https://pypi.org/project/MLB-StatsAPI/
using the "pip install MLB-StatsAPI" command.

There are two functions one for all teams one for a specific team:
boxscore_data_all_teams.py
boxscore_data_one_team.py

------------------------------------------------------------------------------

- After downloading -
From the command line you can:

                                    start_date   end_date
"python boxscore_data_all_teams.py "MM/DD/YYYY" "MM/DD/YYYY" "folder_path_for_xlsx"

or

"python boxscore_data_one_team.py "team name" "MM/DD/YYYY" "MM/DD/YYYY" "folder_path_for_xlsx"

or

Just run it from your IDE. Delete the 'arg.start_date' and other args
from the CL and put in strings. The 'main' is at the bottom in the try except.
The main function is boxscore_data.

----------------------------------------------------------------------------------------

                                  General Details

* Team names are spelt specifically with proper case. Look at "teams_and_ids.py"
ex "New York Yankees", "St. Louis Cardinals", "Los Angeles Angels", "Oakland Athletics"

The columns in the exported DataFrame are:

      -game id: the id the mlbstats api gives this specific game. you can use it in
      other functions as well

      -date: date game was played

      -team: full team name

      -opp: opposing team at that game

      -H: Home or Away. If "Y" the team was home for this game. If "N" they were away.

      -DBH: "Y" or "N" if this game was a double header. "S" is a double header
      just a "split-admission" double header

      -Innings (1-#) - one through max innings. Not all teams reach the max inning played of
      another teams, thus they'll have zeros in those extra columns.

About

Utilizing the MLB-StatsAPI I use a pandas dataframe to organize and collect the amount of runs for a team(s) organized by inning between the dates and export the dataframe to a xlsx.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages