Есть ли кто-нибудь, кто знаком с использованием statsapi (MLB api) и кодированием на Python?Python

Программы на Python
Anonymous
Есть ли кто-нибудь, кто знаком с использованием statsapi (MLB api) и кодированием на Python?

Сообщение Anonymous »


I have several playerId, but I need to retrieve the stats for each season.. Can it be obtained with python code? (coding in ipynb.

.)

import statsapi player_box = {} begin_year, end_year = 1970, 2024 min_debut = f'{begin_year}-01-01' for y in range(begin_year, end_year): players = statsapi.lookup_player(lookup_value='', season=y) for i, p_i in enumerate(players): progress = 100 * ((y - begin_year + i/len(players)) / (end_year - begin_year)) print(f'\rprogress: {progress:.1f}%', end='') if p_i['mlbDebutDate'] < min_debut: continue if not p_i['id'] in player_box: player_box[p_i['id']] = [] player_box[p_i['id']].append(y) print(f'\nTOTAL: {len(player_box)} players') This Python script uses the statsapi library to fetch and record the seasons played by MLB players who debuted between 1970 and 2023. It iterates through each year within this range, queries players, and updates a dictionary with their IDs and the years they played, only including those who debuted after 1970.

For each player, the years they played were stored inside the values of a dictionary.


Источник: https://stackoverflow.com/questions/781 ... -in-python

Вернуться в «Python»