import pandas as pd
pokemon_data = pd.read_csv('pokemon.csv')
pokemon_data = pokemon_data.drop(['japanese_name'], axis = 1) # We don't need japanese_name column for our analysis
pokemon_data.head(5)
# lets grab some visualization libraries for some simple visualizations of our data
import matplotlib.pyplot as plt
import seaborn as sns
# grab only the name column for each generation so we have a definitive count
poke_by_generation = pokemon_data.groupby('generation').count().name
plt.figure(figsize=(10, 10))
bars = plt.bar(range(1 , len(poke_by_generation) + 1), poke_by_generation, width=0.7)
# add some formatting to our plot
plt.ylabel("number of pokemon")
plt.xlabel("generation")
plt.title(label="Pokemon Per Generation", loc="center", fontsize=22)
for bar in bars:
yval = bar.get_height()
plt.text(x = bar.get_x()+0.25, y = yval, s= yval, va='bottom', fontsize=12) # bottom vertical alignment so the number doesn't touch the bar
plt.show()
columns_of_interest = ['height_m', 'weight_kg', 'hp', 'attack', 'sp_attack', 'defense', 'sp_defense', 'speed']
corr_data = pokemon_data[columns_of_interest]
corr_data = corr_data.dropna()
import numpy as np
correlation_coefficients = np.corrcoef( corr_data, rowvar=False )
plt.figure(figsize=(15,8))
sns.heatmap( correlation_coefficients[0:2], annot=True ) # index from 0:2 because we only want to see corrolations between height and weight
plt.xticks( np.arange(8)+0.5, corr_data.columns, rotation = 35 )
plt.yticks( np.arange(2)+0.5, corr_data.columns[0:2], rotation = 0 )
plt.title(label="Pokemon Stats Correlated With Height & Weight", loc="center", fontsize=22)
plt.show()
pokemon_data.loc[pokemon_data['weight_kg'].isna()][['name', 'generation']]
legendary = pokemon_data[pokemon_data['is_legendary'] == True]
non_legendary = pokemon_data[pokemon_data['is_legendary'] == False]
corr_data_legendary = legendary[columns_of_interest].dropna()
corr_data_non_legendary = non_legendary[columns_of_interest].dropna()
plt.figure(figsize=(12,8))
correlation_coefficients = np.corrcoef( corr_data_non_legendary, rowvar=False )
sns.heatmap( correlation_coefficients[0:2], annot=True ) # index from 0:2 because we only want to see corrolations between height and weight
plt.xticks( np.arange(8)+0.5, corr_data.columns, rotation = 35 )
plt.yticks( np.arange(2)+0.5, corr_data.columns[0:2], rotation = 0 )
plt.title(label="Non-Legendary Pokemon Stats Correlated With Height & Weight", loc="center", fontsize=22)
plt.show()
plt.figure(figsize=(12,8))
correlation_coefficients = np.corrcoef( corr_data_legendary, rowvar=False )
sns.heatmap( correlation_coefficients[0:2], annot=True ) # index from 0:2 because we only want to see corrolations between height and weight
plt.xticks( np.arange(8)+0.5, corr_data.columns, rotation = 35 )
plt.yticks( np.arange(2)+0.5, corr_data.columns[0:2], rotation = 0 )
plt.title(label="Legendary Pokemon Stats Correlated With Height & Weight", loc="center", fontsize=22)
plt.show()
import requests # we will use the requests library to call the pokeapi
import json # the response will be easier to work with in JSON, so we opt for the library
# loop through all of our pokedex entries
for pokedex_entry in range(1, pokemon_data.shape[0]):
# make a request to the amazing pokeapi!
request_url = 'https://pokeapi.co/api/v2/pokemon/' + str(pokedex_entry)
response = requests.get(request_url)
# make our JSON response into a python dictionary for ease of mutability
full_response = json.loads(response.text)
image_url = full_response['sprites']['front_default'] # extract the default image URL from the dictionary
pokemon_data.loc[pokedex_entry -1, 'image_url'] = image_url # append to the correct index in the dataframe
# Exporting the csv to be used in our dashboard application
pokemon_data.to_csv('pokemon_data.csv')