Open shitathakin opened 2 years ago
Thanks for the kind words @shitathakin :smile:
This should be possible by iterating over the stats.season_results
list. This is a list of DataFrames, one for each season. Each DataFrame contains per-match stats which contains Goals, Behinds, Kicks, Marks (and a bunch more stats).
See example:
>>> from pyAFL.players.models import Player
>>> player = Player("Nick Riewoldt")
>>> stats = player.get_player_stats()
# `stats.season_results` is a list of Pandas DataFrames. Each DataFrame represents a single season.
>>> stats.season_results[1]
St Kilda - 2002 ...
Gm Opponent Rd R # KI MK HB DI GL BH HO TK ... CL CG FF FA BR CP UP CM MI 1% BO GA %P
0 7.0 Carlton 1 W 12 7 3 2 9 1.0 1.0 1.0 2.0 ... NaN 1.0 NaN 1.0 NaN 3 6 NaN 1.0 1.0 NaN NaN NaN
1 8.0 Fremantle 2 L 12 9 8 2 11 NaN NaN 2.0 1.0 ... NaN NaN NaN NaN NaN 1 10 1.0 1.0 1.0 NaN NaN NaN
2 9.0 Port Adelaide 3 L 12 4 4 5 9 NaN 1.0 NaN 2.0 ... NaN NaN NaN NaN NaN 2 7 1.0 NaN NaN 1.0 NaN NaN
3 10.0 Geelong 4 L 12 10 9 6 16 NaN NaN 3.0 1.0 ... NaN 3.0 2.0 1.0 NaN 5 10 2.0 NaN 3.0 NaN NaN NaN
...
So you will need to iterate through each season and each game. Do you think this access pattern works well enough for what you are doing? If not, happy to hear your thoughts on how you think I can improve the API!
Yep, works I treat. I found that the updates for a players game were very late on afl tables, at least 24 hours after the game had finished. So I ended up making a new function which essentially does the same thing but scraping off footywire instead as the updates are much quicker.
Loving the scraper, works a treat! Any way to get players performance on a game by game basis. for instance Lance Franklin s2022 r7: 4 goals, 5 kicks, 3 marks etc.