jldbc / pybaseball

Pull current and historical baseball statistics using Python (Statcast, Baseball Reference, FanGraphs)
MIT License
1.18k stars 321 forks source link

first pitch result data #390

Closed crodger12 closed 7 months ago

crodger12 commented 8 months ago

import pybaseball import pandas as pd

Fetch the data for the specified date range

data = pybaseball.statcast(start_dt='2023-10-22', end_dt='2023-10-22')

Create filtering conditions for the first pitch of the top and bottom of the first inning

condition_first_inning = (data['pitch_number'] == 1) & (data['inning'] == 1)

Filter the data based on the condition

filtered_data = data[condition_first_inning]

Group by game, inning, and top/bottom of inning, then take the first entry of each group

grouped = filtered_data.groupby(['game_date', 'home_team', 'away_team', 'inning_topbot']).first().reset_index()

Replace 'Top' and 'Bot' values in inning_topbot column with 'T' and 'B'

grouped['inning_T_or_B'] = grouped['inning_topbot'].replace({'Top': 'T', 'Bot': 'B'})

Select the specified columns along with the new inning_T_or_B column

result = grouped[['home_team', 'away_team', 'batter', 'pitcher', 'description', 'inning_T_or_B']]

Optionally, if you want to view the result in your notebook:

print(result)

Data is wrong it was ball and ball for top of first and second

crodger12 commented 8 months ago

I lied grouping error cheers

samlafell commented 8 months ago

@crodger12 Are you saying that you resolved the problem on your own? If so, we can close the issue.

Additionally, please remember to follow some best practices when submitting an issue.

Basic practices like using a virtual environment, installing only the necessary packages, and then including your pip list for that env. Also, whenever posting code, please format the code correctly. Search Google for something like "code blocks in Git issues".

A lot of similarities with asking a Question on StackOverflow, and submitting an issue on Git. And this goes for anyone seeing this, too. Make your issues as reproducible as possible. Meaning, I can build a docker image to match your system (or close to) and include all the versions to make sure I'm seeing the same thing you are.

Thanks for contributing to the repo!

crodger12 commented 8 months ago

yes you are all good to close sorry about that

samlafell commented 7 months ago

@schorrm To mark closed?