API-FOOTBALL

GRATIS CON POSSIBILITÀ DI UPGRADE
Da API-SPORTS | Aggiornamento vor 12 Tagen | Sports
Popolarità

10 / 10

Latenza

366ms

Livello di servizio

100%

Health Check

N/A

Torna a tutte le discussioni

Only returning 20 players from specific league?

Rapid account: Ckelleher Bektqav Qm
ckelleher-BektqavQm
vor 2 Jahren

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 vor 2 Jahren

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 vor 2 Jahren

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 vor 2 Jahren

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

Partecipa alla discussione - aggiungi un commento di seguito:

Accedi/Iscriviti per pubblicare nuovi commenti