1

I'm new to coding and especially new to JSON and I was wondering if there's a way to turn the following output into a table of data. Thanks :)

import json
import requests
manager_history_url = 'https://fantasy.premierleague.com/api/entry/151515/history/'
r = requests.get(manager_history_url).json()
print(r['current'])

2 Answers 2

2

You can use next example to put the data into Panda's dataframe:

import requests
import pandas as pd

manager_history_url = (
    "https://fantasy.premierleague.com/api/entry/151515/history/"
)
r = requests.get(manager_history_url).json()

df = pd.DataFrame(r["current"])
print(df)

Prints:

   event  points  total_points     rank  rank_sort  overall_rank  bank  value  event_transfers  event_transfers_cost  points_on_bench
0      1      68            68  1725839    1732015       1725838     0   1000                0                     0                6
1      2      54           122  5199752    5200844       2942283     0   1000                0                     0                6
2      3      66           188   544944     545247       1068695    14   1001                2                     0                8
3      4      76           264  1701243    1702381        604535    14   1001                0                     0                5
4      5      51           315  7486710    7487155       1936710    14   1003                0                     0                3
5      6      56           371  1609882    1610502       1314429     6   1004                2                     0                3
6      7       0           371  6582907    6630334       1300746     7   1003                1                     0                0
7      8      66           437  1082654    1084716        729789     7   1004                0                     0                0
Sign up to request clarification or add additional context in comments.

Comments

0

My preference is to use Pandas:

import json
import requests
import pandas as pd
manager_history_url = 'https://fantasy.premierleague.com/api/entry/151515/history/'
r = requests.get(manager_history_url).json()
df = pd.DataFrame(r['current'])
print(df)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.