API-FOOTBALL

FREEMIUM
Verified
By API-SPORTS | Updated 11 дней назад | Sports
Popularity

10 / 10

Latency

366ms

Service Level

100%

Health Check

N/A

Back to All Discussions

Only returning 20 players from specific league?

Rapid account: Ckelleher Bektqav Qm
ckelleher-BektqavQm
2 года назад

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

Join in the discussion - add comment below:

Login / Signup to post new comments