Example 1: Pokemon Analysis

This example was extracted from [1] (Chapter 3).


In [1]:
from pivottablejs import pivot_ui
from skdata import SkData

import numpy as np


/home/xmn/miniconda3/envs/skdata/lib/python3.6/site-packages/odo/backends/pandas.py:102: FutureWarning: pandas.tslib is deprecated and will be removed in a future version.
You can access NaTType as type(pandas.NaT)
  @convert.register((pd.Timestamp, pd.Timedelta), (pd.tslib.NaTType, type(None)))

Loading data


In [2]:
sd = SkData('/tmp/pokemon.h5')
sd.import_from('../data/pokemon.json', index_col='id')
sd['pokemon'].summary(compute=True)


Out[2]:
Types Set Values Count Set # Observations # NaN
name object [' Abomasnow', ' Aerodactyl', ' Aggron', ' Alt... 297 297 0
type object [' Bug', ' Dark', ' Dragon', ' Electric', ' Fi... 16 297 0
typeTwo object [' Bug', ' Dark', ' Dragon', ' Electric', ' Fi... 16 297 0

In [3]:
sd['pokemon'].result.head()


Out[3]:
name type typeTwo
1 Bulbasaur Grass Poison
2 Ivysaur Grass Poison
3 Venusaur Grass Poison
6 Charizard Fire Flying
12 Butterfree Bug Flying

Preparing Data


In [4]:
result = sd['pokemon'].result.groupby('type').count()
result = result[['name']].rename(columns={'name': 'total'})
result


Out[4]:
total
type
Bug 45
Dark 16
Dragon 12
Electric 7
Fighting 3
Fire 14
Ghost 10
Grass 31
Ground 17
Ice 11
Normal 29
Poison 11
Psychic 9
Rock 24
Steel 13
Water 45

In [5]:
pivot_ui(result)


Out[5]:

References

[1] CUESTA, Hector; KUMAR, Sampath. Practical Data Analysis. Packt Publishing Ltd, 2016