Skip to content

[BUG] get_player_stats() is broken #2

@a4v2d4

Description

@a4v2d4

Just tried the example script for NBA (examples_nba.py) and ran into this error when script was in the middle of get_player_stats():

Traceback (most recent call last):
  File "examples_nba.py", line 4, in <module>
    df = nba.get_player_stats('Bruno Caboclo')
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.12/site-packages/BRScraper/nba.py", line 346, in get_player_stats
    num = df[df['Season']=='Career'].index[0]
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
  File ".venv/lib/python3.12/site-packages/pandas/core/indexes/base.py", line 5320, in __getitem__
    return getitem(key)
           ^^^^^^^^^^^^
IndexError: index 0 is out of bounds for axis 0 with size 0

Seems issue is with assuming the player's stats table is at index 0 here: df = pd.read_html(url)[0]. I think it should find the table based on the header name "Per Game" or "Totals" instead of assuming same index for each player (diff. players have diff. layouts for diff. reasons).

Most of the rest of the example script works like a charm! Thanks so much for open-sourcing this! Super helpful :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions