API-FOOTBALL

FREEMIUM
Verified
(Ким) API-SPORTS | Оновлено 11日前 | Sports
Популярність

10 / 10

Затримки

366ms

Рівень обслуговування

100%

Health Check

N/A

Повернутися до всіх обговорень

Only returning 20 players from specific league?

Hello - I’m trying to pull player data for a specific league into a pandas DataFrame, but when I run my application, it’s only returning 20 results. Do I need to pass additional parameters to get all players? Is the free version of the API limiting the # of players? Or is it some other issue with what I’m doing?

My code is below:

import requests
import pandas as pd
import json
from dash import Dash, dcc, html, dash_table
import dash_bootstrap_components as dbc
from dash.dash_table.Format import Format, Padding

url = "https://api-football-v1.p.rapidapi.com/v3/players"

querystring = {"league":"39","season":"2020"}

headers = {
	"X-RapidAPI-Host": "api-football-v1.p.rapidapi.com",
	"X-RapidAPI-Key": "xxxxxxx"
}

response = requests.request("GET", url, headers=headers, params=querystring)

comment Check keys of ‘response’

response.json().keys()

commentCheck keys at next level of ‘response’

response.json().keys()

comment Create dictionary of results for ‘players’ key

players_dict = response.json()

comment Create a dataframe from the dictionary

players_df = pd.DataFrame.from_dict(players_dict, orient='index')
Rapid account: Api Sports
api-sports Commented 2年前

You have to call each page in a loop, there is too much data to receive all data in one call.

Best

Rapid account: Ckelleher Bektqav Qm
ckelleher-BektqavQm Commented 2年前

Ok - that’s very helpful, thank you!

For the ‘page’ parameter, is there a way include ‘all’ pages? Or would I have to pass it through a loop to collect every page?

Rapid account: Api Sports
api-sports Commented 2年前

Hi,

This endpoint is paginated with 20 results per page as indicated in the documentation. So you have to add the parameter “page” to see the next results.

As example :

{
get: "players"
parameters: {
league: "39"
season: “2020”
}
errors: [
]
results: 20
paging: {
current: 1
total: 37
}

There is 37 pages for this league id and season.

Best

Приєднуйтесь до обговорення — додайте повідомлення нижче:

Вхід / Реєстрація, щоб публікувати нові повідомлення