-
-
Notifications
You must be signed in to change notification settings - Fork 17
Beginner Project (Pokemon)
- Learn how to access data via an API
GET
request - Transform the output data from
json
into apandas dataframe
- Query and aggregate the data with
pandas
to answer some questions
We are going to be using the pokemon endpoint for REST API for the PokeAPI found here and documentation on this and the other endpoints is found here. Read the documentation for the API and see if you can write a request to return some of the data. An article on how to use the requests
library and API GET
requests here.
To generate the data needed for the rest of the project run the following code (see if you can figure out what the code is doing) and to make things simpler we're limiting ourselves to Gen I:
import requests
import json
url = "https://pokeapi.co/api/v2/pokemon?limit=151&offset=0"
res = requests.get(url)
data = res.json()
output = {}
for pokemon in data["results"]:
res = requests.get(pokemon["url"])
output[pokemon["name"]] = res.json()
This code will give you a nested Python dictionary, you can either use the data in this format or I'd recommend you converting it into a pandas dataframe (how will be left to you!).
Questions:
-
Which pokemon that is a grass type has the largest
hp
stat? -
How many pokemon have
poison
as one of their types? -
Which pokemon has the fewest available moves?
-
Which pokemon type has the fewest members?
-
How many pokemon are in all 8 generations (yes there are 9 generations but only 8 in this API)?
Extra Credit:
Come up with you own question and answer it! (maybe something about stats?)