데이터의 가능성/pandas
01_Pokemon
gamnyam
2024. 6. 10. 18:07
1. 필요한 라이브러리 들을 import 하세요.
import pandas as pd
2. 다음과 같은 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']
}
type(raw_data)
dict
3. pokemon이라는 변수에 DataFrame 을 할당하세요.
pokemon = pd.DataFrame(raw_data)
print(pokemon)
name evolution type hp pokedex
0 Bulbasaur Ivysaur grass 45 yes
1 Charmander Charmeleon fire 39 no
2 Squirtle Wartortle water 44 yes
3 Caterpie Metapod bug 45 no
4. DataFrame 열이 알파벳 순서로 되어있습니다. name, type, hp, evolution, pokedex 의 순서로 column을 배치하세요.
pokemon = pokemon[["name", "type", "hp", "evolution", "pokedex"]]
5. "place" column을 만들고 ['park','street','lake','forest'] 순서로 할당하세요.
place = ['park', 'street', 'lake', 'forest']
pokemon.loc[:,"place"]=place
6. 각 column의 datatype을 확인해보세요.
pokemon.dtypes
name object
type object
hp int64
evolution object
pokedex object
place object
dtype: object
7. 'hp' column의 datatype을 확인해보세요
pokemon.hp.dtype
dtype('int64')
pokemon["hp"].dtype
dtype('int64')