panzarino / mlbgame

A Python API to retrieve and read MLB GameDay data
http://panz.io/mlbgame/
MIT License
529 stars 112 forks source link

AttributeError: 'list' object has no attribute 'hbp' #65

Closed Hisairnessag3 closed 6 years ago

Hisairnessag3 commented 6 years ago
 hbp_home = player_stats.home_batting.hbp
AttributeError: 'list' object has no attribute 'hbp'

^ Getting this error on the player stats object

    for game in games:
        stats = mlbgame.team_stats(game.game_id)
        player_stats = mlbgame.player_stats(game.game_id)
        hbp_home = player_stats.home_batting.hbp

Also is there a way to grab or calculate advanced sabermetrics like wRC, FIP, wOPA, etc for teams(not players) on a game level basis. I am working on some ML models and that would be really helpful. Would do any API work myself just want to know if it can be done.

trevor-viljoen commented 6 years ago

MLB doesn't provide this info as a team stat. You will have to calculate it per player:

player_stats = mlbgame.player_stats(game.game_id)
hbp_home = sum([ p.hbp for p in player_stats.home_batting ])
trevor-viljoen commented 6 years ago

Sabremetrics would have to be calculated based on individual statistics and then summed. Fangraphs has some information on how to calculate stats like wRC, FIP, and wOPA. You should be able to build arrays and then build list comprehension summations from those individual stats.

panzarino commented 6 years ago

@trevor-viljoen has provided the correct answer, closing.