Jupyter-ITVitae/pokémon.ipynb

145 KiB

None <html lang="en"> <head> gitea_input3018089681 </head>
In [2]:
import polars as ps

pokémon = ps.read_csv("./pokémon/Pokemon.csv")
pokémon
Out[2]:
shape: (800, 13)
#NameType 1Type 2TotalHPAttackDefenseSp. AtkSp. DefSpeedGenerationLegendary
i64strstrstri64i64i64i64i64i64i64i64bool
1"Bulbasaur""Grass""Poison"3184549496565451false
2"Ivysaur""Grass""Poison"4056062638080601false
3"Venusaur""Grass""Poison"525808283100100801false
3"VenusaurMega V…"Grass""Poison"62580100123122120801false
4"Charmander""Fire"null3093952436050651false
5"Charmeleon""Fire"null4055864588065801false
6"Charizard""Fire""Flying"534788478109851001false
6"CharizardMega …"Fire""Dragon"63478130111130851001false
6"CharizardMega …"Fire""Flying"63478104781591151001false
7"Squirtle""Water"null3144448655064431false
8"Wartortle""Water"null4055963806580581false
9"Blastoise""Water"null530798310085105781false
712"Bergmite""Ice"null3045569853235286false
713"Avalugg""Ice"null514951171844446286false
714"Noibat""Flying""Dragon"2454030354540556false
715"Noivern""Flying""Dragon"53585708097801236false
716"Xerneas""Fairy"null6801261319513198996true
717"Yveltal""Dark""Flying"6801261319513198996true
718"Zygarde50% For…"Dragon""Ground"6001081001218195956true
719"Diancie""Rock""Fairy"60050100150100150506true
719"DiancieMega Di…"Rock""Fairy"700501601101601101106true
720"HoopaHoopa Con…"Psychic""Ghost"6008011060150130706true
720"HoopaHoopa Unb…"Psychic""Dark"6808016060170130806true
721"Volcanion""Fire""Water"6008011012013090706true
In [3]:
pokémon.sort(ps.col("HP")).tail(1)
Out[3]:
shape: (1, 13)
#NameType 1Type 2TotalHPAttackDefenseSp. AtkSp. DefSpeedGenerationLegendary
i64strstrstri64i64i64i64i64i64i64i64bool
242"Blissey""Normal"null540255101075135552false
In [4]:
from polars import col

pokémon.select(ps.col("Type 2").fill_null(ps.col("Type 1")))
pnn = pokémon.with_columns([
    ps.when(col("Type 2").is_null()).then(col("Type 1")).otherwise(col("Type 2")).alias("Type 2")
])

pnn
Out[4]:
shape: (800, 13)
#NameType 1Type 2TotalHPAttackDefenseSp. AtkSp. DefSpeedGenerationLegendary
i64strstrstri64i64i64i64i64i64i64i64bool
1"Bulbasaur""Grass""Poison"3184549496565451false
2"Ivysaur""Grass""Poison"4056062638080601false
3"Venusaur""Grass""Poison"525808283100100801false
3"VenusaurMega V…"Grass""Poison"62580100123122120801false
4"Charmander""Fire""Fire"3093952436050651false
5"Charmeleon""Fire""Fire"4055864588065801false
6"Charizard""Fire""Flying"534788478109851001false
6"CharizardMega …"Fire""Dragon"63478130111130851001false
6"CharizardMega …"Fire""Flying"63478104781591151001false
7"Squirtle""Water""Water"3144448655064431false
8"Wartortle""Water""Water"4055963806580581false
9"Blastoise""Water""Water"530798310085105781false
712"Bergmite""Ice""Ice"3045569853235286false
713"Avalugg""Ice""Ice"514951171844446286false
714"Noibat""Flying""Dragon"2454030354540556false
715"Noivern""Flying""Dragon"53585708097801236false
716"Xerneas""Fairy""Fairy"6801261319513198996true
717"Yveltal""Dark""Flying"6801261319513198996true
718"Zygarde50% For…"Dragon""Ground"6001081001218195956true
719"Diancie""Rock""Fairy"60050100150100150506true
719"DiancieMega Di…"Rock""Fairy"700501601101601101106true
720"HoopaHoopa Con…"Psychic""Ghost"6008011060150130706true
720"HoopaHoopa Unb…"Psychic""Dark"6808016060170130806true
721"Volcanion""Fire""Water"6008011012013090706true
In [5]:
gen1 = pnn.filter(col("Generation") == 1)
gen1
Out[5]:
shape: (166, 13)
#NameType 1Type 2TotalHPAttackDefenseSp. AtkSp. DefSpeedGenerationLegendary
i64strstrstri64i64i64i64i64i64i64i64bool
1"Bulbasaur""Grass""Poison"3184549496565451false
2"Ivysaur""Grass""Poison"4056062638080601false
3"Venusaur""Grass""Poison"525808283100100801false
3"VenusaurMega V…"Grass""Poison"62580100123122120801false
4"Charmander""Fire""Fire"3093952436050651false
5"Charmeleon""Fire""Fire"4055864588065801false
6"Charizard""Fire""Flying"534788478109851001false
6"CharizardMega …"Fire""Dragon"63478130111130851001false
6"CharizardMega …"Fire""Flying"63478104781591151001false
7"Squirtle""Water""Water"3144448655064431false
8"Wartortle""Water""Water"4055963806580581false
9"Blastoise""Water""Water"530798310085105781false
142"AerodactylMega…"Rock""Flying"615801358570951501false
143"Snorlax""Normal""Normal"5401601106565110301false
144"Articuno""Ice""Flying"580908510095125851true
145"Zapdos""Electric""Flying"580909085125901001true
146"Moltres""Fire""Flying"580901009012585901true
147"Dratini""Dragon""Dragon"3004164455050501false
148"Dragonair""Dragon""Dragon"4206184657070701false
149"Dragonite""Dragon""Flying"6009113495100100801false
150"Mewtwo""Psychic""Psychic"68010611090154901301true
150"MewtwoMega Mew…"Psychic""Fighting"7801061901001541001301true
150"MewtwoMega Mew…"Psychic""Psychic"780106150701941201401true
151"Mew""Psychic""Psychic"6001001001001001001001false
In [6]:
no_megas = pnn.filter(~col("Name").str.contains("Mega "))
no_megas
Out[6]:
shape: (752, 13)
#NameType 1Type 2TotalHPAttackDefenseSp. AtkSp. DefSpeedGenerationLegendary
i64strstrstri64i64i64i64i64i64i64i64bool
1"Bulbasaur""Grass""Poison"3184549496565451false
2"Ivysaur""Grass""Poison"4056062638080601false
3"Venusaur""Grass""Poison"525808283100100801false
4"Charmander""Fire""Fire"3093952436050651false
5"Charmeleon""Fire""Fire"4055864588065801false
6"Charizard""Fire""Flying"534788478109851001false
7"Squirtle""Water""Water"3144448655064431false
8"Wartortle""Water""Water"4055963806580581false
9"Blastoise""Water""Water"530798310085105781false
10"Caterpie""Bug""Bug"1954530352020451false
11"Metapod""Bug""Bug"2055020552525301false
12"Butterfree""Bug""Flying"3956045509080701false
711"GourgeistSuper…"Ghost""Grass"494851001225875546false
712"Bergmite""Ice""Ice"3045569853235286false
713"Avalugg""Ice""Ice"514951171844446286false
714"Noibat""Flying""Dragon"2454030354540556false
715"Noivern""Flying""Dragon"53585708097801236false
716"Xerneas""Fairy""Fairy"6801261319513198996true
717"Yveltal""Dark""Flying"6801261319513198996true
718"Zygarde50% For…"Dragon""Ground"6001081001218195956true
719"Diancie""Rock""Fairy"60050100150100150506true
720"HoopaHoopa Con…"Psychic""Ghost"6008011060150130706true
720"HoopaHoopa Unb…"Psychic""Dark"6808016060170130806true
721"Volcanion""Fire""Water"6008011012013090706true
In [24]:
from plotnine import ggplot, aes, geom_histogram, labs

(
    ggplot(no_megas.to_pandas())
    + aes(x="Attack") 
    + geom_histogram(bins=(200/25))
    + labs(title="Distribution of attack stat for all Pokémon", y="Amount of Pokémon")
)
No description has been provided for this image
In [28]:
only_fairy = pnn.filter(col("Type 1").str.contains("Fairy") | col("Type 2").str.contains("Fairy"))

(
    ggplot(only_fairy.to_pandas())
    + aes(x="Generation") 
    + geom_histogram(bins=(6), color='#EF9FEF', fill='#EF6FEF')
    + labs(title="Amount of fairy Pokémon in each generation", y="Amount of Pokémon")
)
No description has been provided for this image
</html>