jldbc / pybaseball

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

Batting_stats_range #329

Closed educhaj closed 1 year ago

educhaj commented 1 year ago

Hey, I keep getting a "list index out of range" when I run this. Thanks for keeping this up!

tjburch commented 1 year ago

I'm assuming you're trying to do a ST game from this year.

For this query:

>>> batting_stats_range()
start_dt 2023-02-27
end_dt 2023-02-28
Warning: no date range supplied, assuming yesterday's date.

The url is: http://www.baseball-reference.com/leagues/daily.cgi?user_team=&bust_cache=&type=b&lastndays=7&dates=fromandto&fromandto=2023-02-27.2023-02-28&level=mlb&franch=&stat=&stat_value=0

Looks like bbref doesn't have anything from ST this year.

For contrast,

>>> batting_stats_range("2022-04-13", "2022-04-20")

gives: http://www.baseball-reference.com/leagues/daily.cgi?user_team=&bust_cache=&type=b&lastndays=7&dates=fromandto&fromandto=2022-04-13.2022-04-20&level=mlb&franch=&stat=&stat_value=0

where you'll see a table filled. I believe the statcast queries are up to date with ST, might consider using one of those and doing groupbys to get what you want.

educhaj commented 1 year ago

Thanks! I was trying to do last year, but it seems to be working now. Not sure what happened.