{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
evolutionhpnamepokedextype
0Ivysaur45Bulbasauryesgrass
1Charmeleon39Charmandernofire
2Wartortle44Squirtleyeswater
3Metapod45Caterpienobug
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nametypehpevolutionpokedex
0Bulbasaurgrass45Ivysauryes
1Charmanderfire39Charmeleonno
2Squirtlewater44Wartortleyes
3Caterpiebug45Metapodno
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nametypehpevolutionpokedexplace
0Bulbasaurgrass45Ivysauryespark
1Charmanderfire39Charmeleonnostreet
2Squirtlewater44Wartortleyeslake
3Caterpiebug45Metapodnoforest
\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 }