Professional Documents
Culture Documents
Infant Mortality Rates OECD
Infant Mortality Rates OECD
0.0.2 Imports
[4]: data.head()
Flag Codes
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
[5]: data.describe()
1
[5]: TIME Value
count 2365.000000 2365.000000
mean 1988.661311 20.369725
std 16.229813 24.748055
min 1960.000000 0.700000
25% 1975.000000 5.600000
50% 1989.000000 11.900000
75% 2003.000000 22.800000
max 2016.000000 165.100000
[6]: data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2365 entries, 0 to 2364
Data columns (total 8 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 LOCATION 2365 non-null object
1 INDICATOR 2365 non-null object
2 SUBJECT 2365 non-null object
3 MEASURE 2365 non-null object
4 FREQUENCY 2365 non-null object
5 TIME 2365 non-null int64
6 Value 2365 non-null float64
7 Flag Codes 7 non-null object
dtypes: float64(1), int64(1), object(6)
memory usage: 147.9+ KB
[7]: data.groupby('LOCATION').count()
2
FIN 57 57 57 57 57 57 0
FRA 57 57 57 57 57 57 2
GBR 57 57 57 57 57 57 1
GRC 57 57 57 57 57 57 0
HUN 57 57 57 57 57 57 0
IDN 56 56 56 56 56 56 0
IND 56 56 56 56 56 56 0
IRL 57 57 57 57 57 57 0
ISL 57 57 57 57 57 57 0
ISR 47 47 47 47 47 47 0
ITA 57 57 57 57 57 57 0
JPN 57 57 57 57 57 57 0
KOR 23 23 23 23 23 23 0
LTU 57 57 57 57 57 57 0
LUX 57 57 57 57 57 57 0
LVA 57 57 57 57 57 57 0
MEX 55 55 55 55 55 55 0
NLD 57 57 57 57 57 57 0
NOR 57 57 57 57 57 57 0
NZL 55 55 55 55 55 55 0
POL 57 57 57 57 57 57 0
PRT 57 57 57 57 57 57 0
RUS 37 37 37 37 37 37 2
SVK 57 57 57 57 57 57 1
SVN 57 57 57 57 57 57 0
SWE 57 57 57 57 57 57 0
TUR 21 21 21 21 21 21 0
USA 56 56 56 56 56 56 0
ZAF 42 42 42 42 42 42 0
3
867 KOR INFANTMORTALITY TOT DEATH_1000BIRTH A 2008
868 KOR INFANTMORTALITY TOT DEATH_1000BIRTH A 2009
869 KOR INFANTMORTALITY TOT DEATH_1000BIRTH A 2010
870 KOR INFANTMORTALITY TOT DEATH_1000BIRTH A 2011
871 KOR INFANTMORTALITY TOT DEATH_1000BIRTH A 2012
872 KOR INFANTMORTALITY TOT DEATH_1000BIRTH A 2013
873 KOR INFANTMORTALITY TOT DEATH_1000BIRTH A 2014
874 KOR INFANTMORTALITY TOT DEATH_1000BIRTH A 2015
875 KOR INFANTMORTALITY TOT DEATH_1000BIRTH A 2016
1499 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 1996
1500 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 1997
1501 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 1998
1502 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 1999
1503 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2000
1504 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2001
1505 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2002
1506 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2003
1507 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2004
1508 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2005
1509 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2006
1510 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2007
1511 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2008
1512 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2009
1513 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2010
1514 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2011
1515 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2012
1516 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2013
1517 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2014
1518 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2015
1519 TUR INFANTMORTALITY TOT DEATH_1000BIRTH A 2016
4
868 3.2 NaN
869 3.2 NaN
870 3.0 NaN
871 2.9 NaN
872 3.0 NaN
873 3.0 NaN
874 2.7 NaN
875 2.8 NaN
1499 40.9 NaN
1500 38.8 NaN
1501 36.5 NaN
1502 33.9 NaN
1503 28.4 NaN
1504 28.6 NaN
1505 29.6 NaN
1506 29.1 NaN
1507 27.4 NaN
1508 25.8 NaN
1509 24.5 NaN
1510 16.5 NaN
1511 15.7 NaN
1512 13.9 NaN
1513 12.0 NaN
1514 11.6 NaN
1515 11.6 NaN
1516 10.8 NaN
1517 11.1 NaN
1518 10.2 NaN
1519 10.0 NaN
[11]: country_names.head()
[13]: data_plus.head()
5
[13]: LOCATION INDICATOR SUBJECT MEASURE FREQUENCY TIME Value \
0 AUS INFANTMORTALITY TOT DEATH_1000BIRTH A 1960 20.2
1 AUS INFANTMORTALITY TOT DEATH_1000BIRTH A 1961 19.5
2 AUS INFANTMORTALITY TOT DEATH_1000BIRTH A 1962 20.4
3 AUS INFANTMORTALITY TOT DEATH_1000BIRTH A 1963 19.5
4 AUS INFANTMORTALITY TOT DEATH_1000BIRTH A 1964 19.1
[14]: data_plus.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2365 entries, 0 to 2364
Data columns (total 10 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 LOCATION 2365 non-null object
1 INDICATOR 2365 non-null object
2 SUBJECT 2365 non-null object
3 MEASURE 2365 non-null object
4 FREQUENCY 2365 non-null object
5 TIME 2365 non-null int64
6 Value 2365 non-null float64
7 Flag Codes 7 non-null object
8 COUNTRY 2365 non-null object
9 GDP (BILLIONS) 2365 non-null float64
dtypes: float64(2), int64(1), object(7)
memory usage: 203.2+ KB
0.2 Plotly
[15]: #Use Plotly in offline mode
init_notebook_mode(connected=True)
cf.go_offline()
6
countries.append(country)
# make figure
figure = {
'data': [],
'layout': {},
'frames': []
}
'initialValue': str(firstyear),
'plotlycommand': 'animate',
'values': years,
'visible': True}
figure['layout']['updatemenus'] = [{
'buttons': [{'args': [None, {'frame': {'duration': 500,
'redraw': False},
'fromcurrent': True,
'transition': {'duration': 300,
'easing': 'quadratic-in-out'}}],
'label': 'Play',
'method': 'animate'},
{'args': [[None], {'frame': {'duration': 0,
'redraw': False},
'mode': 'immediate',
'transition': {'duration': 0}}],
'label': 'Pause',
'method': 'animate'}],
'direction': 'left',
'pad': {'r': 10, 't': 87},
'showactive': False,
'type': 'buttons',
'x': 0.1,
'xanchor': 'right',
'y': 0,
'yanchor': 'top'}]
7
sliders_dict = {
'active': 0,
'yanchor': 'top',
'xanchor': 'left',
'currentvalue': {
'font': {'size': 20},
'prefix': 'Year:',
'visible': True,
'xanchor': 'right'},
'transition': {'duration': 300, 'easing': 'cubic-in-out'},
'pad': {'b': 10, 't': 50},
'len': 0.9,
'x': 0.1,
'y': 0,
'steps': []}
# make data
# make frames
for year in years:
frame = {'data': [], 'name': str(year)}
for country in countries:
dataset_by_year = data_plus[data_plus['TIME'] == int(year)]
dataset_by_year_and_cont = dataset_by_year[dataset_by_year['COUNTRY']␣
,→== country]
if dataset_by_year_and_cont.empty:
data_dict = {
'x': [0],
'y': [country],
'mode': 'markers',
'text': [0],
'name': country}
else:
data_dict = {
'x': list(dataset_by_year_and_cont['Value']),
'y': list(dataset_by_year_and_cont['COUNTRY']),
'mode': 'markers',
'text': list(dataset_by_year_and_cont['Value']),
'name': country}
if year == firstyear:
figure['data'].append(data_dict)
frame['data'].append(data_dict)
figure['frames'].append(frame)
slider_step = {'args': [[year],
{'frame': {'duration': 300, 'redraw': False},
8
'mode': 'immediate',
'transition': {'duration': 300}}],
'label': year,
'method': 'animate'}
sliders_dict['steps'].append(slider_step)
figure['layout']['sliders'] = [sliders_dict]
# figure['data']
[16]: 'animation.html'
[23]: data_xp.head()
9
fig.update(layout = {'autosize': False, 'width':1000,'height':1000})
[26]: 'chorfig.html'
[27]: 'ani_express.html'
[ ]:
10