Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
guipsamora
GitHub Repository: guipsamora/pandas_exercises
Path: blob/master/08_Creating_Series_and_DataFrames/Pokemon/Exercises-with-solutions-and-code.ipynb
547 views
Kernel: Python 2

Pokemon

Introduction:

This time you will create the data.

Step 1. Import the necessary libraries

import pandas as pd

Step 2. Create a data dictionary

raw_data = {"name": ['Bulbasaur', 'Charmander','Squirtle','Caterpie'], "evolution": ['Ivysaur','Charmeleon','Wartortle','Metapod'], "type": ['grass', 'fire', 'water', 'bug'], "hp": [45, 39, 44, 45], "pokedex": ['yes', 'no','yes','no'] }

Step 3. Assign it to a variable called pokemon

pokemon = pd.DataFrame(raw_data) pokemon.head()

Step 4. Ops...it seems the DataFrame columns are in alphabetical order. Place the order of the columns as name, type, hp, evolution, pokedex

pokemon = pokemon[['name', 'type', 'hp', 'evolution','pokedex']] pokemon

Step 5. Add another column called place, and insert what you have in mind.

pokemon['place'] = ['park','street','lake','forest'] pokemon

Step 6. Present the type of each column

pokemon.dtypes
name object type object hp int64 evolution object pokedex object dtype: object

BONUS: Create your own question and answer it.