An Exploratory Analysis of Pokémon Types
When looking at potential API’s to use for this assignment, I decided I wanted to look at data for fun topics that I have an interest in. I have played Pokémon games since I was around five years old and one aspect that I have always been interested in is which Pokémon types are the most frequent in game and which types are the least frequent. This is a non-obvious insight as people would not know this information without doing research on the game or catching each type in every game. By understanding which Pokémon types are the most and least frequent, players will be able to target types that are rare in the game while avoiding common types.
The data that could answer this question lives on https://pokeapi.co/. PokeAPI is a widely used API that provides a variety of Pokémon related information for interested users to work with. This data is relevant as it provides data for every Pokémon from the original Pokémon Red and Blue games to the newer Pokémon Black and White games. The API includes data about the type for each Pokémon, so I will be able to see how many Pokémon there are for each type.
The main libraries that I used within this assignment were Requests, JSON, Pandas, and Matplotlib.pyplot. With the requests library I made a get request to the specific URL of each Pokémon using the API documentation. Next, I used the JSON library as the API data was structured as a JSON string. The json.loads() method converted the JSON string into a Python Dictionary. I then used the Pandas library to convert the Python Dictionary into a DataFrame object which is easier to work with.
I decided to use a bar graph to visualize Pokémon type data as it is a categorical variable. After looking at the results above it is clear to see that the water Pokémon type is the most common type across the first five Pokémon games. In the beginning of each Pokémon game, the player is given a choice between three starting Pokémon: a water type, a fire type, and a grass type. Out of 650 Pokémon, there are about 100 water type Pokémon, 60 grass type Pokémon, and 40 fire type Pokémon. Using the insights gathered above we know that choosing a fire type for your starting Pokémon is most likely the best choice as it will be easier to find water and grass Pokémon later in the game to add to your party.
One aspect of this dataset that provided a challenge was the fact that many Pokémon have multiple types. When I was looking at the initial results for Pokémon types I was shocked to see how few flying type Pokémon there were according to the data. However, after looking a bit deeper into it I realized that many flying type Pokémon are also normal types, so the flying type was pushed to the second type for these Pokémon. I was able to visualize the second types of each Pokémon and found that although many Pokémon don’t have a second type, around 75 have a second type that is flying. This drastically changed my outlook as the flying type went from being the least common type to the third most common type.
One limitation of this API is the amount of Pokémon data available. There are around 900 individual Pokémon as of 2022, but within this dataset I was only able to access 650. When I originally looked at the Python Dictionary that json.loads() returned, I saw that the first key value pair was a count of 1,126 which I believed meant that there were 1,126 Pokémon in the dataset. However, after attempting to use the count of 1,126 as the range in my for loop, I kept receiving an IndexError for a list index being out of range. After looking into the data more and noticed that the error occurred at the 650th index and onward which coincided with the last Pokémon in the Black and White games. Perhaps if I was able to look at a complete dataset of every individual Pokémon created then the results would look different.