Skip to content

Beginner Project (Pokemon)

Sophia Alice edited this page Jan 16, 2023 · 1 revision

Goals

  1. Learn how to access data via an API GET request
  2. Transform the output data from json into a pandas dataframe
  3. Query and aggregate the data with pandas to answer some questions

Project

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:

  1. Which pokemon that is a grass type has the largest hp stat?

  2. How many pokemon have poison as one of their types?

  3. Which pokemon has the fewest available moves?

  4. Which pokemon type has the fewest members?

  5. 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?)

Help

Our Intro to Programming Tutorial

Clone this wiki locally