{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pokemon"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Introduction:\n",
"\n",
"This time you will create the data.\n",
"\n",
"\n",
"\n",
"### Step 1. Import the necessary libraries"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 2. Create a data dictionary"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"raw_data = {\"name\": ['Bulbasaur', 'Charmander','Squirtle','Caterpie'],\n",
" \"evolution\": ['Ivysaur','Charmeleon','Wartortle','Metapod'],\n",
" \"type\": ['grass', 'fire', 'water', 'bug'],\n",
" \"hp\": [45, 39, 44, 45],\n",
" \"pokedex\": ['yes', 'no','yes','no'] \n",
" }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 3. Assign it to a variable called "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"
\n",
" \n",
" \n",
" | \n",
" evolution | \n",
" hp | \n",
" name | \n",
" pokedex | \n",
" type | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Ivysaur | \n",
" 45 | \n",
" Bulbasaur | \n",
" yes | \n",
" grass | \n",
"
\n",
" \n",
" | 1 | \n",
" Charmeleon | \n",
" 39 | \n",
" Charmander | \n",
" no | \n",
" fire | \n",
"
\n",
" \n",
" | 2 | \n",
" Wartortle | \n",
" 44 | \n",
" Squirtle | \n",
" yes | \n",
" water | \n",
"
\n",
" \n",
" | 3 | \n",
" Metapod | \n",
" 45 | \n",
" Caterpie | \n",
" no | \n",
" bug | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" evolution hp name pokedex type\n",
"0 Ivysaur 45 Bulbasaur yes grass\n",
"1 Charmeleon 39 Charmander no fire\n",
"2 Wartortle 44 Squirtle yes water\n",
"3 Metapod 45 Caterpie no bug"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pokemon = pd.DataFrame(raw_data)\n",
"pokemon.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 4. Ops...it seems the DataFrame columns are in alphabetical order. Place the order of the columns as name, type, hp, evolution, pokedex"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" \n",
" | \n",
" name | \n",
" type | \n",
" hp | \n",
" evolution | \n",
" pokedex | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Bulbasaur | \n",
" grass | \n",
" 45 | \n",
" Ivysaur | \n",
" yes | \n",
"
\n",
" \n",
" | 1 | \n",
" Charmander | \n",
" fire | \n",
" 39 | \n",
" Charmeleon | \n",
" no | \n",
"
\n",
" \n",
" | 2 | \n",
" Squirtle | \n",
" water | \n",
" 44 | \n",
" Wartortle | \n",
" yes | \n",
"
\n",
" \n",
" | 3 | \n",
" Caterpie | \n",
" bug | \n",
" 45 | \n",
" Metapod | \n",
" no | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name type hp evolution pokedex\n",
"0 Bulbasaur grass 45 Ivysaur yes\n",
"1 Charmander fire 39 Charmeleon no\n",
"2 Squirtle water 44 Wartortle yes\n",
"3 Caterpie bug 45 Metapod no"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pokemon = pokemon[['name', 'type', 'hp', 'evolution','pokedex']]\n",
"pokemon"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 5. Add another column called place, and insert what you have in mind."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" \n",
" | \n",
" name | \n",
" type | \n",
" hp | \n",
" evolution | \n",
" pokedex | \n",
" place | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Bulbasaur | \n",
" grass | \n",
" 45 | \n",
" Ivysaur | \n",
" yes | \n",
" park | \n",
"
\n",
" \n",
" | 1 | \n",
" Charmander | \n",
" fire | \n",
" 39 | \n",
" Charmeleon | \n",
" no | \n",
" street | \n",
"
\n",
" \n",
" | 2 | \n",
" Squirtle | \n",
" water | \n",
" 44 | \n",
" Wartortle | \n",
" yes | \n",
" lake | \n",
"
\n",
" \n",
" | 3 | \n",
" Caterpie | \n",
" bug | \n",
" 45 | \n",
" Metapod | \n",
" no | \n",
" forest | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name type hp evolution pokedex place\n",
"0 Bulbasaur grass 45 Ivysaur yes park\n",
"1 Charmander fire 39 Charmeleon no street\n",
"2 Squirtle water 44 Wartortle yes lake\n",
"3 Caterpie bug 45 Metapod no forest"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pokemon['place'] = ['park','street','lake','forest']\n",
"pokemon"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 6. Present the type of each column"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"name object\n",
"type object\n",
"hp int64\n",
"evolution object\n",
"pokedex object\n",
"dtype: object"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pokemon.dtypes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### BONUS: Create your own question and answer it."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}