Comments (12)
@BrayanMnz Thanks for following up! Desired output is a method to determine whether a player is actually a pitcher (as opposed to a position player who has pitched) or actually a position player (as opposed to a pitcher who has recorded some ABs). From a tangible perspective, maybe the desired output would be a list of all players in history with IDs and that pitcher/position information. and in that list, Babe Ruth and Shoei Ohtani would have 2 rows (or maybe 1 row with the value 'both') indicating that they are legitimately both.
here's the hack I've developed so far...
def identify_hitters_and_pitchers():
appearances_df = spark.createDataFrame( appearances() )
appearances_df = appearances_df
.withColumn( 'games_in_the_field', f.col('G_c') + f.col('G_1b') + f.col('G_2b') + f.col('G_3b') +
f.col('G_ss') + f.col('G_lf') + f.col('G_cf') + f.col('G_rf') + f.col('G_dh') )
.withColumnRenamed( 'G_p', 'games_pitched' )
.withColumnRenamed( 'playerID', 'bbrefID' )
positions_df = appearances_df.groupBy( ['bbrefID'] )
.agg( f.sum( 'games_pitched' ).alias( 'games_pitched' ),
f.sum( 'games_in_the_field' ).alias( 'games_in_the_field' ) )
.withColumn( 'position', f.when( f.col( 'games_pitched' ) >= f.col( 'games_in_the_field' ), 'pitcher' ).otherwise( 'hitter' ) )
return positions_df
from pybaseball.
Could someone submit a pull request to change the following code in split_stats.py per the below?
I'm unable to push changes from databricks to GitHub at the moment and I need to spend some time getting that worked out (if anyone has tips, I'd be grateful).
Old
about_info = soup.find_all( "div", {"itemtype": "https://schema.org/Person"})
New
about_info = soup.find_all( "div", id="info", class_=re.compile("players") )
from pybaseball.
figured it out...
#314
from pybaseball.
I'm thinking that appearances() from the lahman database is the best way to deduce this info. specifically, iterate over the games played at each position and select the position where the player played most of their games as that player's position
from pybaseball.
What is your desired output @TobiasCortese,
could you add an example ?
from pybaseball.
Looking forward to see your Pull Request with these changes.
Looks promising.
from pybaseball.
So it looks like the info is available from get_splits()
player_info: Boolean. Optional. If set to True, the get_splits function will return both the split stats dataframe and a dictionary of player info that contains player position, handedness, height, weight, and team
but I'm getting an index out of range error when attempting to execute the sample code
from pybaseball.
so, since you figured out how to solve that issue - is the splits() working now ? @TobiasCortese
from pybaseball.
Hey @BrayanMnz - I'm not sure I understand the question.
there was never any problem with this method...
get_splits('troutmi01')
but this method generates an error...
get_splits('troutmi01', player_info=True)
so i downloaded the code locally, made adjustments, got it working, tested it and then forked the repo, created a branch and pushed the branch to main (pull request 314, which is currently outstanding). So the code works on my machine but is still broken in production.
from pybaseball.
Hi Tobias, still broken on production because the PR has not been merged yet - it will be available on production once it get into the master branch and we made a release.
from pybaseball.
Yep. That process generally aligns with standard practices and is as expected, and I've been tracking the status of the PR since inception. Thanks for confirming.
from pybaseball.
Thanks @TobiasCortese! See my comment in your PR (#314), this was covered in #318. Appreciate the sleuthing and finding this, sorry it got doubled up,
from pybaseball.
Related Issues (20)
- Pulling Park Factors from baseball savant
- pitching_stats(year) not working for some seasons HOT 2
- statcast_pitcher does not apply sanitize_input
- retrosheet.py returns an error for all functions HOT 1
- team_game_logs not pulling HOT 2
- Statcast Ball Counts > 3
- How to Get a Pitcher's Season-to-Date ERA heading into a specific date/game_pk?
- Minor League Statcast data
- Future Warnings in team_game_logs
- pitching_stats_range - occasionally not working
- Convert dtypes issue? HOT 2
- pitching_stats and batting_stats not returning all data HOT 3
- Imports HOT 6
- Missing cLI data interferes with streak calculation
- Shota Imanaga key_fangraphs value -1 HOT 2
- Cache Generates Massive Amounts of Empty Files HOT 1
- I couldn't collect players season stats
- Pip install pybaseball differs from code on master branch HOT 1
- Github Token
- mypy errors caused by Python type hints
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pybaseball.