Issue
Hello CS community,
r = requests.get("https://pokeapi.co/api/v2/pokemon/")
x = r.json()
df = pd.DataFrame(x['results'])
I am using these lines to get the data from this api to my jupyter notebook for my big data class but somehow I am getting only 19 lines/rows. Could you please help me load the whole data? Or should it be somehow by 19 and then delete and other 19?
Thank you guys!
Solution
Looks like the api
is loading only 20
records at a time.
If you see carefully, it has a next
key in it. You can do something like this:
In [467]: r = requests.get("https://pokeapi.co/api/v2/pokemon/")
In [471]: x = r.json()
In [476]: data = []
In [477]: data.append(x['results'])
# Loop until `next` is `None`
In [478]: while x.get('next'):
...: r = requests.get("https://pokeapi.co/api/v2/pokemon/")
...: x = r.json()
...: data.append(x['results'])
...:
In [473]: df = pd.DataFrame(data)
This should get you all the records.
Answered By - Mayank Porwal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.