0% found this document useful (0 votes)
49 views3 pages

Pokemon With Error - Ipynb - Colaboratory

The document analyzes a Pokemon dataset using Python. It loads the Pokemon CSV data, adds an index column, and displays the first 10 records. Various cross tabulations and plots are created to analyze Pokemon attributes like generation, base happiness, attacks, and whether they are legendary. A histogram compares legendary and non-legendary Pokemon across generations. The document also bins the attack stats and creates a cross tabulation and bar plot based on attack bins and legendary status. It concludes by printing the timestamp.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views3 pages

Pokemon With Error - Ipynb - Colaboratory

The document analyzes a Pokemon dataset using Python. It loads the Pokemon CSV data, adds an index column, and displays the first 10 records. Various cross tabulations and plots are created to analyze Pokemon attributes like generation, base happiness, attacks, and whether they are legendary. A histogram compares legendary and non-legendary Pokemon across generations. The document also bins the attack stats and creates a cross tabulation and bar plot based on attack bins and legendary status. It concludes by printing the timestamp.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

9/15/23, 2:00 PM Pokemon with error.

ipynb - Colaboratory

#Enter your name


name = "Clanza, Marion Brent A."
print("Name: ", name)

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
pokemon = pd.read_csv("/content/pokemon.csv")

#Output shape of the dataset


pokemon.shape

#Add an index field


pokemon['index'] = pd.Series(range(0,len(pokemon)))

#Show first 10 records of the dataset


pokemon.head(10)

#Create a bar chart showing the number of pokemon per generation


#Use pkm variable.
pkm = sns.countplot(x = 'generation', data = pokemon)

#Create a crosstab of the data based on generation and base_happiness


crosstab_01 = pd.crosstab(pokemon['generation'], pokemon['base_happiness'])

#Plot the crosstab data using a stacked bar type


crosstab_01.plot(kind = 'bar', stacked = True)

#Create crosstab of data to plot using div to sum within each row of the table
crosstab_norm = crosstab_01.div(crosstab_01.sum(1), axis = 0)

#Plot a normalized crosstab data


crosstab_norm.plot(kind = 'bar', stacked = True)

#Create another crosstab showing the legendary and generation


crosstab_02 = pd.crosstab(pokemon['is_legendary'], pokemon['generation'])

#Obtain percentage of the legendary pokemon based on its generation


print(crosstab_02.div(crosstab_02.sum(0), axis = 1)*100, 1)

#Using the percentage data, create a subset for each element of the overlay
#is_legendary overlay generation
pkm_y = pokemon[pokemon.is_legendary == 1]['generation']
pkm_n = pokemon[pokemon.is_legendary == 0]['generation']

#Create a histogram based on the two subsets


plt.hist([pkm_y, pkm_n], bins = 10, stacked = True)

#Save the output from the non-normalized plot into variables


(n, bins, patches) = plt.hist([pkm_y, pkm_n], bins = 10, stacked = True)

#Use the cut function in Pandas to create the bins under 20, 20 to 60 and over 100
#Based on attack
pokemon['VAR'] = pd.cut(x = pokemon['attack'], bins = [0, 20, 60, 100,], labels=["Under 20", "20 to 60", "Over 100"], right = False)

#Create the crosstab of attack_binned based on legendary and non-legendary


crosstab_02 = pd.crosstab(pokemon['VAR'], pokemon['is_legendary'])

#Then plot a crosstab data based on VAR


crosstab_02.plot(kind = 'bar', stacked = True, title = 'Bar Graph of Attack (Binned)')

### END ###

#Using datetime
from datetime import datetime
import pytz
tz = pytz.timezone('Asia/Manila')
manila_now = datetime.now(tz)
#Print timestamp
print("Timestamp:", manila_now)

https://colab.research.google.com/drive/10u73ZWDSYVlL46PcHkAovl4z5zKClFM1#printMode=true 1/3
9/15/23, 2:00 PM Pokemon with error.ipynb - Colaboratory

Name: Clanza, Marion Brent A.


generation 1 2 3 4 5 6 \
is_legendary
0 96.688742 94.0 92.592593 87.850467 91.666667 91.666667
1 3.311258 6.0 7.407407 12.149533 8.333333 8.333333

generation 7
is_legendary
0 78.75
1 21.25 1
Timestamp: 2023-09-15 14:00:08.714969+08:00

https://colab.research.google.com/drive/10u73ZWDSYVlL46PcHkAovl4z5zKClFM1#printMode=true 2/3
9/15/23, 2:00 PM Pokemon with error.ipynb - Colaboratory

Colab paid products - Cancel contracts here

check 1s completed at 2:00 PM

https://colab.research.google.com/drive/10u73ZWDSYVlL46PcHkAovl4z5zKClFM1#printMode=true 3/3

You might also like