{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# In Search Of Happiness: What If Health?\n", "\n", "Let's continue our happiness challenge! Previously, we found out the happiest places on the planet. You can read about this and much more [here](https://nbviewer.jupyter.org/github/chupstee/data.sugar/blob/master/00002_world_happiness/world_happiness.map.ipynb). \n", "And now we would like to know whether the level of happiness is associated with health. \n", "We'll take [the same report from Kaggle](https://www.kaggle.com/unsdsn/world-happiness?select=2019.csv), which ranks 156 countries by their level of happiness on a 10-point scale.\n", "\n", "\n", "## The World Happiness Report\n", "\n", "Recall quoting Kaggle:\n", "\n", "The World Happiness Report is a landmark survey of the state of global happiness. The first report was published in 2012, the second in 2013, the third in 2015, and the fourth in the 2016 Update. The World Happiness 2017, which ranks 155 countries by their happiness levels, was released at the United Nations at an event celebrating International Day of Happiness on March 20th. The report continues to gain global recognition as governments, organizations and civil society increasingly use happiness indicators to inform their policy-making decisions. Leading experts across fields – economics, psychology, survey analysis, national statistics, health, public policy and more – describe how measurements of well-being can be used effectively to assess the progress of nations. The reports review the state of happiness in the world today and show how the new science of happiness explains personal and national variations in happiness.\n", "\n", "You can read more [here](https://www.kaggle.com/unsdsn/world-happiness).\n", "\n", "We are most interested in the following columns:\n", "\n", "- `Country or region` - country name\n", "- `Overall rank` - country's place in the rating\n", "- `Score` - happiness score\n", "\n", "\n", "## Introduction\n", "\n", "So, what is happiness? Or, better yet, are there any patterns in people's happiness?\n", "\n", "[The World Factbook](https://www.cia.gov/library/publications/the-world-factbook) by CIA provides information on the history, people and society, government, economy, energy, geography, communications, transportation, military, and transnational issues for 267 world entities. \n", "What is interesting for us in this project is to compare the level of happiness of the country and such health indicators as:\n", "\n", "- `Obesity` - adult prevalence rate gives the percent of a country's population considered to be obese.\n", "- `Maternal mortality rate` (`MMR`) - the annual number of female deaths per 100,000 live births from any cause related to or aggravated by pregnancy or its management (excluding accidental or incidental causes).\n", "- `Infant mortality rate` - the number of deaths of infants under one year old in a given year per 1,000 live births in the same year. This rate is often used as an indicator of the level of health in a country.\n", "- `Total fertility rate` (`TFR`) - the average number of children that would be born per woman if all women lived to the end of their childbearing years and bore children according to a given fertility rate at each age. TFR is a more direct measure of the level of fertility than the crude birth rate, since it refers to births per woman.\n", "- `HIV/AIDS - adult prevalence rate` - an estimate of the percentage of adults (aged 15-49) living with HIV/AIDS. The adult prevalence rate is calculated by dividing the estimated number of adults living with HIV/AIDS at yearend by the total adult population at yearend.\n", "- `HIV/AIDS - deaths` - the number of adults and children who died of AIDS during a given calendar year.\n", "\n", "We will compare the happiness scores with the CIA rates for 2016, as this is the year when the data is presented in the most complete way. \n", "\n", "In the search for an answer to the question ***what*** *is happiness?*, let's try to establish *the relationship between happiness and health indicators*.\n", "\n", "\n", "## Reading The Data" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Import libs\n", "from glob import glob\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Happiness Reports\n", "\n", "As we mentioned above, we'll read the happiness report, published in 2016. \n", "We'll also rename the columns according to the snake_case format." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['country', 'region', 'rank', 'score', 'whisker_low', 'whisker_high', 'gdp_per_capita', 'family',\n", " 'life_expectancy', 'freedom', 'trust_corruption', 'generosity', 'dystopia_residual'],\n", " dtype='object')\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countryregionrankscorewhisker_lowwhisker_highgdp_per_capitafamilylife_expectancyfreedomtrust_corruptiongenerositydystopia_residual
0DenmarkWestern Europe17.5267.4607.5921.441781.163740.795040.579410.444530.361712.73939
1SwitzerlandWestern Europe27.5097.4287.5901.527331.145240.863030.585570.412030.280832.69463
2IcelandWestern Europe37.5017.3337.6691.426661.183260.867330.566240.149750.476782.83137
3NorwayWestern Europe47.4987.4217.5751.577441.126900.795790.596090.357760.378952.66465
4FinlandWestern Europe57.4137.3517.4751.405981.134640.810910.571040.410040.254922.82596
\n", "
" ], "text/plain": [ " country region rank score whisker_low whisker_high gdp_per_capita family life_expectancy \\\n", "0 Denmark Western Europe 1 7.526 7.460 7.592 1.44178 1.16374 0.79504 \n", "1 Switzerland Western Europe 2 7.509 7.428 7.590 1.52733 1.14524 0.86303 \n", "2 Iceland Western Europe 3 7.501 7.333 7.669 1.42666 1.18326 0.86733 \n", "3 Norway Western Europe 4 7.498 7.421 7.575 1.57744 1.12690 0.79579 \n", "4 Finland Western Europe 5 7.413 7.351 7.475 1.40598 1.13464 0.81091 \n", "\n", " freedom trust_corruption generosity dystopia_residual \n", "0 0.57941 0.44453 0.36171 2.73939 \n", "1 0.58557 0.41203 0.28083 2.69463 \n", "2 0.56624 0.14975 0.47678 2.83137 \n", "3 0.59609 0.35776 0.37895 2.66465 \n", "4 0.57104 0.41004 0.25492 2.82596 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Set the width to display\n", "pd.set_option('display.width', 120)\n", "# Increase the number of rows to display\n", "pd.set_option('display.max_rows', 60) \n", "\n", "# Get the data\n", "happiness = pd.read_csv('data/happiness_2016.csv')\n", "\n", "# Column map to rename\n", "cols_dict = {'Country':'country',\n", " 'Country or region':'country',\n", " 'Region':'region',\n", " 'Happiness Rank':'rank',\n", " 'Happiness.Rank':'rank',\n", " 'Overall rank':'rank',\n", " 'Happiness Score':'score',\n", " 'Happiness.Score':'score',\n", " 'Score':'score',\n", " 'Economy (GDP per Capita)':'gdp_per_capita',\n", " 'Economy..GDP.per.Capita.':'gdp_per_capita',\n", " 'GDP per capita':'gdp_per_capita',\n", " 'Family':'family',\n", " 'Freedom':'freedom',\n", " 'Freedom to make life choices':'freedom',\n", " 'Generosity':'generosity',\n", " 'Health (Life Expectancy)':'life_expectancy',\n", " 'Health..Life.Expectancy.':'life_expectancy',\n", " 'Healthy life expectancy':'life_expectancy',\n", " 'Perceptions of corruption':'trust_corruption',\n", " 'Trust (Government Corruption)':'trust_corruption',\n", " 'Trust..Government.Corruption.':'trust_corruption',\n", " 'Social support':'social_support',\n", " 'Dystopia Residual':'dystopia_residual',\n", " 'Dystopia.Residual':'dystopia_residual',\n", " 'Standard Error':'standard_error',\n", " 'Upper Confidence Interval':'whisker_high',\n", " 'Whisker.high':'whisker_high',\n", " 'Lower Confidence Interval':'whisker_low',\n", " 'Whisker.low':'whisker_low'\n", " }\n", "\n", "# Rename the columns\n", "happiness.rename(columns=cols_dict, inplace=True)\n", "\n", "print(happiness.columns) # check the new column names\n", "happiness.head() # check the values" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "RangeIndex: 157 entries, 0 to 156\n", "Data columns (total 13 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 country 157 non-null object \n", " 1 region 157 non-null object \n", " 2 rank 157 non-null int64 \n", " 3 score 157 non-null float64\n", " 4 whisker_low 157 non-null float64\n", " 5 whisker_high 157 non-null float64\n", " 6 gdp_per_capita 157 non-null float64\n", " 7 family 157 non-null float64\n", " 8 life_expectancy 157 non-null float64\n", " 9 freedom 157 non-null float64\n", " 10 trust_corruption 157 non-null float64\n", " 11 generosity 157 non-null float64\n", " 12 dystopia_residual 157 non-null float64\n", "dtypes: float64(10), int64(1), object(2)\n", "memory usage: 16.1+ KB\n" ] } ], "source": [ "happiness.info()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We see 157 countries in the report of 2016. There are no missing values for the `country`, `rank`, `score` columns.\n", "\n", "Let's check for duplicates." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Duplicated: 0\n" ] } ], "source": [ "# Duplicated\n", "print('Duplicated: {}'.format(happiness.duplicated(subset='country').sum()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It's OK. Let's get the CIA data.\n", "\n", "### CIA Reports\n", "\n", "We have downloaded The World Factbook archive for different years and saved the data that was collected in 2016." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initialize: hiv_aids\n", "Merge hiv_aids_death: 110\n", "Merge infant_mortality: 226\n", "Merge mmr: 226\n", "Merge obesity: 227\n", "Merge tfr: 227\n", "\n", "Int64Index: 227 entries, 0 to 226\n", "Data columns (total 7 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 country_cia 227 non-null object \n", " 1 hiv_aids 109 non-null float64\n", " 2 hiv_aids_death 63 non-null float64\n", " 3 infant_mortality 225 non-null float64\n", " 4 mmr 184 non-null float64\n", " 5 obesity 192 non-null float64\n", " 6 tfr 224 non-null float64\n", "dtypes: float64(6), object(1)\n", "memory usage: 14.2+ KB\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
country_ciahiv_aidshiv_aids_deathinfant_mortalitymmrobesitytfr
0Swaziland27.23900.050.4389.016.52.74
1Lesotho25.09900.047.6487.016.62.68
2Botswana21.93900.08.6129.018.92.30
3South Africa18.9110000.032.0138.028.32.31
4Namibia13.84300.036.4265.017.23.36
........................
222SingaporeNaNNaN2.410.06.10.82
223IcelandNaNNaN2.13.021.92.01
224JapanNaNNaN2.05.04.31.41
225MonacoNaNNaN1.8NaNNaN1.53
226NiueNaNNaNNaNNaN50.0NaN
\n", "

227 rows × 7 columns

\n", "
" ], "text/plain": [ " country_cia hiv_aids hiv_aids_death infant_mortality mmr obesity tfr\n", "0 Swaziland 27.2 3900.0 50.4 389.0 16.5 2.74\n", "1 Lesotho 25.0 9900.0 47.6 487.0 16.6 2.68\n", "2 Botswana 21.9 3900.0 8.6 129.0 18.9 2.30\n", "3 South Africa 18.9 110000.0 32.0 138.0 28.3 2.31\n", "4 Namibia 13.8 4300.0 36.4 265.0 17.2 3.36\n", ".. ... ... ... ... ... ... ...\n", "222 Singapore NaN NaN 2.4 10.0 6.1 0.82\n", "223 Iceland NaN NaN 2.1 3.0 21.9 2.01\n", "224 Japan NaN NaN 2.0 5.0 4.3 1.41\n", "225 Monaco NaN NaN 1.8 NaN NaN 1.53\n", "226 Niue NaN NaN NaN NaN 50.0 NaN\n", "\n", "[227 rows x 7 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cia_files = glob('data/cia.health.*.201?.txt')\n", "cia = pd.DataFrame()\n", "\n", "for file in cia_files:\n", " c = pd.read_csv(file,\n", " engine='python', sep=r'\\s{3,}', header=None, names=['country_cia', file.split('.')[2]],\n", " squeeze=False, skiprows=0, index_col=[0],\n", " thousands=',', dtype={file.split('.')[2]:'float64'}\n", " ) # read the file\n", " if cia.size == 0:\n", " cia = cia.append(c)\n", " print('Initialize: {}'.format(file.split('.')[2], cia.shape[0])) # for the first file\n", " else:\n", " cia = cia.merge(c, on='country_cia', how='outer')\n", " print('Merge {}: {}'.format(file.split('.')[2], cia.shape[0]))\n", "\n", "cia.reset_index()\n", "\n", "cia.info()\n", "cia" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Preparing The Data Sets\n", "\n", "Now we should combine the `happiness` and `cia` datasets.\n", "\n", "First, we need to check the columns that will be used for merging.\n", "Country names may differ in data sets, for instance, `eSwatini` and `Swaziland`, `Trinidad and Tobago` and `Trinidad & Tobago`. In this case, the rows will not match.\n", "\n", "Before, we store the `country_cia` column of the `cia` in a new column `country`." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "cia['country'] = cia['country_cia']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's compare the `country` columns of the `happiness` data set and the `cia` data set.\n", "To do this, we'll combine two data sets using `outer` join." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countryscoreinfant_mortality
138Ivory Coast3.916NaN
126Congo (Brazzaville)4.236NaN
124Congo (Kinshasa)4.272NaN
118Myanmar4.395NaN
107Palestinian Territories4.754NaN
96Somaliland Region5.057NaN
87Montenegro5.161NaN
76Kosovo5.401NaN
61North Cyprus5.771NaN
57South Korea5.835NaN
26Czech Republic6.596NaN
209American SamoaNaN8.5
228AndorraNaN3.6
230AnguillaNaN3.4
196Antigua and BarbudaNaN12.5
200ArubaNaN11.0
162Bahamas, TheNaN11.7
168BarbadosNaN10.5
234BermudaNaN2.5
195British Virgin IslandsNaN12.6
206BruneiNaN9.9
172BurmaNaN42.2
171Cabo VerdeNaN22.7
215Cayman IslandsNaN6.0
161Central African RepublicNaN88.4
173Congo, Democratic Republic of theNaN69.8
163Congo, Republic of theNaN56.4
192Cook IslandsNaN13.5
165Cote d'IvoireNaN57.2
175CubaNaN4.5
212CuracaoNaN7.7
233CzechiaNaN2.6
169DjiboutiNaN47.2
201DominicaNaN10.9
160Equatorial GuineaNaN67.2
174EritreaNaN45.6
226European UnionNaN4.0
217Faroe IslandsNaN5.5
176FijiNaN9.7
221French PolynesiaNaN4.7
166Gambia, TheNaN62.0
187Gaza StripNaN17.1
216GibraltarNaN6.0
207GreenlandNaN9.0
205GrenadaNaN9.9
218GuamNaN5.3
229GuernseyNaN3.4
164Guinea-BissauNaN87.5
167GuyanaNaN31.5
225Isle of ManNaN4.1
227JerseyNaN3.8
180KiribatiNaN33.2
182Korea, NorthNaN22.9
232Korea, SouthNaN3.0
158LesothoNaN47.6
224LiechtensteinNaN4.3
231MacauNaN3.1
183MaldivesNaN22.9
185Marshall IslandsNaN20.0
184Micronesia, Federated States ofNaN20.5
235MonacoNaN1.8
194MontserratNaN12.7
159MozambiqueNaN67.9
211NauruNaN7.9
219New CaledoniaNaN5.3
236NiueNaNNaN
220Northern Mariana IslandsNaN5.3
193OmanNaN13.2
202PalauNaN10.9
170Papua New GuineaNaN37.4
191Saint Helena, Ascension, and Tristan da CunhaNaN13.7
208Saint Kitts and NevisNaN8.6
199Saint LuciaNaN11.2
213Saint Pierre and MiquelonNaN6.6
197Saint Vincent and the GrenadinesNaN12.3
186SamoaNaN19.0
223San MarinoNaN4.4
178Sao Tome and PrincipeNaN46.6
204SeychellesNaN10.2
210Sint MaartenNaN8.3
188Solomon IslandsNaN15.2
157SwazilandNaN50.4
179Timor-LesteNaN36.3
198TongaNaN11.6
203Turks and Caicos IslandsNaN10.4
181TuvaluNaN29.9
189VanuatuNaN15.1
214Virgin IslandsNaN6.5
222Wallis and FutunaNaN4.4
190West BankNaN14.6
177Western SaharaNaN53.3
\n", "
" ], "text/plain": [ " country score infant_mortality\n", "138 Ivory Coast 3.916 NaN\n", "126 Congo (Brazzaville) 4.236 NaN\n", "124 Congo (Kinshasa) 4.272 NaN\n", "118 Myanmar 4.395 NaN\n", "107 Palestinian Territories 4.754 NaN\n", "96 Somaliland Region 5.057 NaN\n", "87 Montenegro 5.161 NaN\n", "76 Kosovo 5.401 NaN\n", "61 North Cyprus 5.771 NaN\n", "57 South Korea 5.835 NaN\n", "26 Czech Republic 6.596 NaN\n", "209 American Samoa NaN 8.5\n", "228 Andorra NaN 3.6\n", "230 Anguilla NaN 3.4\n", "196 Antigua and Barbuda NaN 12.5\n", "200 Aruba NaN 11.0\n", "162 Bahamas, The NaN 11.7\n", "168 Barbados NaN 10.5\n", "234 Bermuda NaN 2.5\n", "195 British Virgin Islands NaN 12.6\n", "206 Brunei NaN 9.9\n", "172 Burma NaN 42.2\n", "171 Cabo Verde NaN 22.7\n", "215 Cayman Islands NaN 6.0\n", "161 Central African Republic NaN 88.4\n", "173 Congo, Democratic Republic of the NaN 69.8\n", "163 Congo, Republic of the NaN 56.4\n", "192 Cook Islands NaN 13.5\n", "165 Cote d'Ivoire NaN 57.2\n", "175 Cuba NaN 4.5\n", "212 Curacao NaN 7.7\n", "233 Czechia NaN 2.6\n", "169 Djibouti NaN 47.2\n", "201 Dominica NaN 10.9\n", "160 Equatorial Guinea NaN 67.2\n", "174 Eritrea NaN 45.6\n", "226 European Union NaN 4.0\n", "217 Faroe Islands NaN 5.5\n", "176 Fiji NaN 9.7\n", "221 French Polynesia NaN 4.7\n", "166 Gambia, The NaN 62.0\n", "187 Gaza Strip NaN 17.1\n", "216 Gibraltar NaN 6.0\n", "207 Greenland NaN 9.0\n", "205 Grenada NaN 9.9\n", "218 Guam NaN 5.3\n", "229 Guernsey NaN 3.4\n", "164 Guinea-Bissau NaN 87.5\n", "167 Guyana NaN 31.5\n", "225 Isle of Man NaN 4.1\n", "227 Jersey NaN 3.8\n", "180 Kiribati NaN 33.2\n", "182 Korea, North NaN 22.9\n", "232 Korea, South NaN 3.0\n", "158 Lesotho NaN 47.6\n", "224 Liechtenstein NaN 4.3\n", "231 Macau NaN 3.1\n", "183 Maldives NaN 22.9\n", "185 Marshall Islands NaN 20.0\n", "184 Micronesia, Federated States of NaN 20.5\n", "235 Monaco NaN 1.8\n", "194 Montserrat NaN 12.7\n", "159 Mozambique NaN 67.9\n", "211 Nauru NaN 7.9\n", "219 New Caledonia NaN 5.3\n", "236 Niue NaN NaN\n", "220 Northern Mariana Islands NaN 5.3\n", "193 Oman NaN 13.2\n", "202 Palau NaN 10.9\n", "170 Papua New Guinea NaN 37.4\n", "191 Saint Helena, Ascension, and Tristan da Cunha NaN 13.7\n", "208 Saint Kitts and Nevis NaN 8.6\n", "199 Saint Lucia NaN 11.2\n", "213 Saint Pierre and Miquelon NaN 6.6\n", "197 Saint Vincent and the Grenadines NaN 12.3\n", "186 Samoa NaN 19.0\n", "223 San Marino NaN 4.4\n", "178 Sao Tome and Principe NaN 46.6\n", "204 Seychelles NaN 10.2\n", "210 Sint Maarten NaN 8.3\n", "188 Solomon Islands NaN 15.2\n", "157 Swaziland NaN 50.4\n", "179 Timor-Leste NaN 36.3\n", "198 Tonga NaN 11.6\n", "203 Turks and Caicos Islands NaN 10.4\n", "181 Tuvalu NaN 29.9\n", "189 Vanuatu NaN 15.1\n", "214 Virgin Islands NaN 6.5\n", "222 Wallis and Futuna NaN 4.4\n", "190 West Bank NaN 14.6\n", "177 Western Sahara NaN 53.3" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "happiness_cia = happiness.merge(cia, on='country', how='outer')[['country', 'score', 'infant_mortality']]\n", "\n", "pd.set_option('display.max_rows', 100) # increase the number of rows to display\n", "happiness_cia[happiness_cia.isnull().any(axis=1)].sort_values(by=['score', 'country']) # the countries don't match" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To provide the same country names:\n", "\n", "- Create a dictionary mapping all names to the values in the `happiness` dataset since we explore the happiness data.\n", "- Rename the countries in the `cia` dataset by replacing the values according to the map dictionary." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
country_ciahiv_aidshiv_aids_deathinfant_mortalitymmrobesitytfrcountry
172Puerto RicoNaNNaN7.414.0NaN1.64Puerto Rico
214LuxembourgNaNNaN3.410.022.61.61Luxembourg
46Papua New Guinea0.91100.037.4215.021.33.10Papua New Guinea
168NauruNaNNaN7.9NaN61.02.84Nauru
21Cote d'Ivoire2.725000.057.2645.010.33.46Ivory Coast
\n", "
" ], "text/plain": [ " country_cia hiv_aids hiv_aids_death infant_mortality mmr obesity tfr country\n", "172 Puerto Rico NaN NaN 7.4 14.0 NaN 1.64 Puerto Rico\n", "214 Luxembourg NaN NaN 3.4 10.0 22.6 1.61 Luxembourg\n", "46 Papua New Guinea 0.9 1100.0 37.4 215.0 21.3 3.10 Papua New Guinea\n", "168 Nauru NaN NaN 7.9 NaN 61.0 2.84 Nauru\n", "21 Cote d'Ivoire 2.7 25000.0 57.2 645.0 10.3 3.46 Ivory Coast" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Countries map to rename\n", "country_to_rename = {'Cote d\\'Ivoire':'Ivory Coast',\n", " 'Congo, Republic of the':'Congo (Brazzaville)',\n", " 'Congo, Democratic Republic of the':'Congo (Kinshasa)',\n", " 'Burma':'Myanmar',\n", " 'Korea, South':'South Korea',\n", " 'Czechia':'Czech Republic'\n", " }\n", "# Rename the countries\n", "cia['country'].replace(country_to_rename, inplace=True)\n", "\n", "cia.sample(5, random_state=5) # check the values randomly" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can now use the `country` column to merge the two datasets." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Int64Index: 157 entries, 0 to 156\n", "Data columns (total 20 columns):\n", " # Column Non-Null Count Dtype \n", "--- ------ -------------- ----- \n", " 0 country 157 non-null object \n", " 1 region 157 non-null object \n", " 2 rank 157 non-null int64 \n", " 3 score 157 non-null float64\n", " 4 whisker_low 157 non-null float64\n", " 5 whisker_high 157 non-null float64\n", " 6 gdp_per_capita 157 non-null float64\n", " 7 family 157 non-null float64\n", " 8 life_expectancy 157 non-null float64\n", " 9 freedom 157 non-null float64\n", " 10 trust_corruption 157 non-null float64\n", " 11 generosity 157 non-null float64\n", " 12 dystopia_residual 157 non-null float64\n", " 13 country_cia 153 non-null object \n", " 14 hiv_aids 93 non-null float64\n", " 15 hiv_aids_death 56 non-null float64\n", " 16 infant_mortality 152 non-null float64\n", " 17 mmr 151 non-null float64\n", " 18 obesity 150 non-null float64\n", " 19 tfr 152 non-null float64\n", "dtypes: float64(16), int64(1), object(3)\n", "memory usage: 25.8+ KB\n" ] } ], "source": [ "happiness_cia = happiness.merge(cia, on='country', how='left').copy()\n", "\n", "happiness_cia.info()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's build a correlation matrix by columns." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countryregionscoreobesitytfrmmrinfant_mortalityhiv_aidshiv_aids_death
0DenmarkWestern Europe7.52619.71.736.04.0NaNNaN
1SwitzerlandWestern Europe7.50919.51.555.03.6NaNNaN
2IcelandWestern Europe7.50121.92.013.02.1NaNNaN
3NorwayWestern Europe7.49823.11.865.02.5NaNNaN
4FinlandWestern Europe7.41322.21.753.02.5NaNNaN
..............................
152BeninSub-Saharan Africa3.4849.64.86405.054.21.02400.0
153AfghanistanSouthern Asia3.3605.55.22396.0112.8NaNNaN
154TogoSub-Saharan Africa3.3038.44.43368.043.72.15100.0
155SyriaMiddle East and Northern Africa3.06927.82.5568.015.2NaNNaN
156BurundiSub-Saharan Africa2.9055.46.04712.060.41.12900.0
\n", "

157 rows × 9 columns

\n", "
" ], "text/plain": [ " country region score obesity tfr mmr infant_mortality hiv_aids \\\n", "0 Denmark Western Europe 7.526 19.7 1.73 6.0 4.0 NaN \n", "1 Switzerland Western Europe 7.509 19.5 1.55 5.0 3.6 NaN \n", "2 Iceland Western Europe 7.501 21.9 2.01 3.0 2.1 NaN \n", "3 Norway Western Europe 7.498 23.1 1.86 5.0 2.5 NaN \n", "4 Finland Western Europe 7.413 22.2 1.75 3.0 2.5 NaN \n", ".. ... ... ... ... ... ... ... ... \n", "152 Benin Sub-Saharan Africa 3.484 9.6 4.86 405.0 54.2 1.0 \n", "153 Afghanistan Southern Asia 3.360 5.5 5.22 396.0 112.8 NaN \n", "154 Togo Sub-Saharan Africa 3.303 8.4 4.43 368.0 43.7 2.1 \n", "155 Syria Middle East and Northern Africa 3.069 27.8 2.55 68.0 15.2 NaN \n", "156 Burundi Sub-Saharan Africa 2.905 5.4 6.04 712.0 60.4 1.1 \n", "\n", " hiv_aids_death \n", "0 NaN \n", "1 NaN \n", "2 NaN \n", "3 NaN \n", "4 NaN \n", ".. ... \n", "152 2400.0 \n", "153 NaN \n", "154 5100.0 \n", "155 NaN \n", "156 2900.0 \n", "\n", "[157 rows x 9 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Select the columns of interest\n", "cols_corr = ['country', 'region', 'score',\n", " 'obesity', 'tfr',\n", " 'mmr', 'infant_mortality',\n", " 'hiv_aids', 'hiv_aids_death'\n", " ]\n", "happiness_cia = happiness_cia[cols_corr]\n", "happiness_cia" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
scoreobesitytfrmmrinfant_mortalityhiv_aidshiv_aids_death
score1.0000000.558845-0.649370-0.615258-0.703726-0.303608-0.017830
obesity0.5588451.000000-0.540814-0.589450-0.638373-0.068440-0.021306
tfr-0.649370-0.5408141.0000000.8225100.8826130.2158090.053922
mmr-0.615258-0.5894500.8225101.0000000.8369170.1649970.141207
infant_mortality-0.703726-0.6383730.8826130.8369171.0000000.1062350.074404
hiv_aids-0.303608-0.0684400.2158090.1649970.1062351.0000000.314998
hiv_aids_death-0.017830-0.0213060.0539220.1412070.0744040.3149981.000000
\n", "
" ], "text/plain": [ " score obesity tfr mmr infant_mortality hiv_aids hiv_aids_death\n", "score 1.000000 0.558845 -0.649370 -0.615258 -0.703726 -0.303608 -0.017830\n", "obesity 0.558845 1.000000 -0.540814 -0.589450 -0.638373 -0.068440 -0.021306\n", "tfr -0.649370 -0.540814 1.000000 0.822510 0.882613 0.215809 0.053922\n", "mmr -0.615258 -0.589450 0.822510 1.000000 0.836917 0.164997 0.141207\n", "infant_mortality -0.703726 -0.638373 0.882613 0.836917 1.000000 0.106235 0.074404\n", "hiv_aids -0.303608 -0.068440 0.215809 0.164997 0.106235 1.000000 0.314998\n", "hiv_aids_death -0.017830 -0.021306 0.053922 0.141207 0.074404 0.314998 1.000000" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get correlation matrix\n", "happiness_cia_corr = happiness_cia.corr()\n", "happiness_cia_corr" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It seems, there are explicitely relationships between some parameters. We'll look at them further. \n", "Let's continue with the plots.\n", "\n", "## Correlation Map\n", "\n", "We'll plot the correlation matrix below, but first, we'll prepare the data to make the plot easier to read." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# A triangular mask to avoid repeated values\n", "happiness_cia_corr = happiness_cia_corr.iloc[1:, :-1]\n", "mask = np.triu(np.ones_like(happiness_cia_corr), k=1)\n", "\n", "# Readable names for the plot\n", "cols_dict = {'score':'Happiness',\n", " 'hiv_aids':'HIV/AIDS',\n", " 'hiv_aids_death':'HIV/AIDS\\ndeath',\n", " 'infant_mortality':'Infant\\nmortality',\n", " 'mmr':'Maternal\\nmortality',\n", " 'tfr':'Total\\nfertility',\n", " 'obesity':'Obesity'\n", " }\n", "# Rename columns in the correlation matrix\n", "happiness_cia_corr.rename(columns=cols_dict, index=cols_dict, inplace=True)" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "# Turn on svg rendering\n", "%config InlineBackend.figure_format = 'svg'\n", "\n", "# Color palette for the blog\n", "snark_palette = ['#e0675a', # red\n", " '#5ca0af', # green\n", " '#edde7e', # yellow\n", " '#211c47' # dark blue\n", " ]" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\r\n", "\r\n", "\r\n", "\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " 2020-10-13T22:34:20.203543\r\n", " image/svg+xml\r\n", " \r\n", " \r\n", " Matplotlib v3.3.1, https://matplotlib.org/\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", "\r\n" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Color palette for the data\n", "palette = [snark_palette[0], # red\n", " 'lightgrey',\n", " snark_palette[1] # green\n", " ]\n", "\n", "# Inscriptions\n", "title = \"\"\"Relationship Between Health Indicators And The Happiness score\"\"\"\n", "description = \"\"\"\n", "Сorrelation of health indicators with the happiness score by country based on 2016 data.\n", "Data: Gallup World Poll - www.kaggle.com/unsdsn/world-happiness & CIA - www.cia.gov/library/publications/the-world-factbook | Author: @data.sugar\n", "\"\"\"\n", "\n", "# Plot size\n", "figsize = (6,4)\n", "\n", "# Set the figure\n", "sns.set(context='paper', style='ticks', palette=palette,\n", " rc={'xtick.bottom':False, 'ytick.left':False, \n", " 'axes.spines.left': False, 'axes.spines.bottom': False,\n", " 'axes.spines.right': False, 'axes.spines.top': False\n", " }\n", " )\n", "\n", "# Create the plot\n", "fig, ax = plt.subplots(1, 1, figsize=figsize, facecolor='w')\n", "sns.heatmap(happiness_cia_corr, mask=mask, cmap=palette,\n", " vmin=-1, vmax=1, center=0,\n", " square=False, linewidths=.5, annot=True, fmt='.2g',\n", " cbar_kws={'shrink': 1, 'ticks':[], 'label':'-1 negative <- correlation -> positive +1'},\n", " ax=ax)\n", "\n", "# Set some aesthetic params for the plot\n", "ax.set_title(title, fontdict={'fontsize': 16}, loc='center', pad=10, c=snark_palette[-1]) # set a title of the plot\n", "ax.annotate(description, xy=(20, -4), size=6, xycoords='figure points', c=snark_palette[-1])\n", "ax.tick_params(axis='both', colors=snark_palette[-1]) # set x/y ticks\n", "\n", "# Save and plot\n", "plt.savefig('plot.pic/plot.happiness.health.png', dpi=150, bbox_inches='tight')\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We expected some correlation between the HIV/AIDS rates and the happiness score, but there is no such correlation. \n", "Indeed, the higher the level of obesity, the higher the happiness index, but this relationship is not very strict. \n", "Let's plot these correlations.\n", "\n", "## Obesity And Happiness" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "\r\n", "\r\n", "\r\n", "\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " 2020-10-13T22:34:23.257514\r\n", " image/svg+xml\r\n", " \r\n", " \r\n", " Matplotlib v3.3.1, https://matplotlib.org/\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", "\r\n" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Inscriptions\n", "title = \"\"\"The Relationship Between Obesity And Happiness\"\"\"\n", "description = \"\"\"\n", "Correlation of the obesity rate with the happiness score by country based on 2016 data.\n", "Data: Gallup World Poll - www.kaggle.com/unsdsn/world-happiness & CIA - www.cia.gov/library/publications/the-world-factbook | Author: @data.sugar\n", "\"\"\"\n", "\n", "# Plot size\n", "figsize = (6,4)\n", "\n", "# Set the figure\n", "sns.set(context='paper', style='ticks', palette=snark_palette,\n", " rc={'xtick.major.size': 4, 'ytick.major.size':4,\n", " 'axes.spines.left': False, 'axes.spines.bottom': False,\n", " 'axes.spines.right': False, 'axes.spines.top': False\n", " }\n", " )\n", "\n", "# Create the plot\n", "fig = plt.figure(figsize=figsize, facecolor='w')\n", "g = sns.jointplot(x='score', y='obesity', data=happiness_cia,\n", " kind='reg', truncate=False, dropna=True,\n", " xlim=(2, 8), ylim=(0, 40),\n", " marginal_kws=dict(hist=True, bins=10),\n", " color=snark_palette[1]\n", " )\n", "\n", "# Set some aesthetic params for the plot\n", "g.ax_marg_x.set_title(title, fontdict={'fontsize': 16}, loc='center', pad=10, c=snark_palette[-1]) # set a title of the plot\n", "g.ax_marg_x.annotate(description, xy=(0.015, -0.01), size=6, xycoords='figure fraction', c=snark_palette[-1])\n", "g.ax_joint.set_xlabel('Happiness score', loc='center', size='x-large', c=snark_palette[-1]) # set label of x axis\n", "g.ax_joint.set_ylabel('Obesity rate', loc='center', size='x-large', c=snark_palette[-1]) # set label of x axis\n", "g.ax_joint.tick_params(axis='both', labelsize='large', colors=snark_palette[-1]) # set x/y ticks\n", "g.ax_joint.spines['bottom'].set_color(snark_palette[-1]) # color x axis\n", "g.ax_joint.spines['left'].set_color(snark_palette[-1]) # color y axis\n", "g.ax_marg_x.tick_params(axis='x', bottom=False) # disable x margin ticks\n", "g.ax_marg_x.spines['bottom'].set_color(snark_palette[1])\n", "g.ax_marg_y.tick_params(axis='y', left=False) # disable y margin ticks\n", "g.ax_marg_y.spines['left'].set_color(snark_palette[1])\n", "\n", "# Save and plot\n", "plt.savefig('plot.pic/plot.happiness.health.obesity.png', dpi=150, bbox_inches='tight')\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Total Fertility Rate And Happiness Score" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "\r\n", "\r\n", "\r\n", "\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " 2020-10-13T22:34:26.618576\r\n", " image/svg+xml\r\n", " \r\n", " \r\n", " Matplotlib v3.3.1, https://matplotlib.org/\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", "\r\n" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Inscriptions\n", "title = \"\"\"The Relationship Between Total Fertility And Happiness\"\"\"\n", "description = \"\"\"\n", "Correlation of the total fertility rate with the happiness score by country based on 2016 data.\n", "Data: Gallup World Poll - www.kaggle.com/unsdsn/world-happiness & CIA - www.cia.gov/library/publications/the-world-factbook | Author: @data.sugar\n", "\"\"\"\n", "\n", "# Plot size\n", "figsize = (6,4)\n", "\n", "# Set the figure\n", "sns.set(context='paper', style='ticks', palette=snark_palette,\n", " rc={'xtick.major.size': 4, 'ytick.major.size':4,\n", " 'axes.spines.left': False, 'axes.spines.bottom': False,\n", " 'axes.spines.right': False, 'axes.spines.top': False\n", " }\n", " )\n", "\n", "# Create the plot\n", "fig = plt.figure(figsize=figsize, facecolor='w')\n", "g = sns.jointplot(x='score', y='tfr', data=happiness_cia,\n", " kind='reg', truncate=False, dropna=True,\n", " xlim=(2, 8), ylim=(0, 7),\n", " marginal_kws=dict(hist=True, bins=8),\n", " color=snark_palette[0]\n", " )\n", "\n", "# Set some aesthetic params for the plot\n", "g.ax_marg_x.set_title(title, fontdict={'fontsize': 16}, loc='center', pad=10, c=snark_palette[-1]) # set a title of the plot\n", "g.ax_marg_x.annotate(description, xy=(0.015, -0.01), size=6, xycoords='figure fraction', c=snark_palette[-1])\n", "g.ax_joint.set_xlabel('Happiness score', loc='center', size='x-large', c=snark_palette[-1]) # set label of x axis\n", "g.ax_joint.set_ylabel('Total fertility rate', loc='center', size='x-large', c=snark_palette[-1]) # set label of x axis\n", "g.ax_joint.tick_params(axis='both', labelsize='large', colors=snark_palette[-1]) # set x/y ticks\n", "g.ax_joint.spines['bottom'].set_color(snark_palette[-1]) # color x axis\n", "g.ax_joint.spines['left'].set_color(snark_palette[-1]) # color y axis\n", "g.ax_marg_x.tick_params(axis='x', bottom=False) # disable x margin ticks\n", "g.ax_marg_x.spines['bottom'].set_color(snark_palette[0])\n", "g.ax_marg_y.tick_params(axis='y', left=False) # disable y margin ticks\n", "g.ax_marg_y.spines['left'].set_color(snark_palette[0])\n", "\n", "# Save and plot\n", "plt.savefig('plot.pic/plot.happiness.health.tfr.png', dpi=150, bbox_inches='tight')\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Infant Mortality Rate And Happiness Score" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "\r\n", "\r\n", "\r\n", "\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " 2020-10-13T22:34:29.773727\r\n", " image/svg+xml\r\n", " \r\n", " \r\n", " Matplotlib v3.3.1, https://matplotlib.org/\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", "\r\n" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Inscriptions\n", "title = \"\"\"The Relationship Between Infant Mortality And Happiness\"\"\"\n", "description = \"\"\"\n", "Correlation of the infant mortality rate with the happiness score by country based on 2016 data.\n", "Data: Gallup World Poll - www.kaggle.com/unsdsn/world-happiness & CIA - www.cia.gov/library/publications/the-world-factbook | Author: @data.sugar\n", "\"\"\"\n", "\n", "# Plot size\n", "figsize = (6,4)\n", "\n", "# Set the figure\n", "sns.set(context='paper', style='ticks', palette=snark_palette,\n", " rc={'xtick.major.size': 4, 'ytick.major.size':4,\n", " 'axes.spines.left': False, 'axes.spines.bottom': False,\n", " 'axes.spines.right': False, 'axes.spines.top': False\n", " }\n", " )\n", "\n", "# Create the plot\n", "fig = plt.figure(figsize=figsize, facecolor='w')\n", "g = sns.jointplot(x='score', y='infant_mortality', data=happiness_cia,\n", " kind='reg', truncate=False, dropna=True,\n", " xlim=(2, 8), ylim=(0, 125),\n", " marginal_kws=dict(hist=True, bins=10),\n", " color=snark_palette[0]\n", " )\n", "\n", "# Set some aesthetic params for the plot\n", "g.ax_marg_x.set_title(title, fontdict={'fontsize': 16}, loc='center', pad=10, c=snark_palette[-1]) # set a title of the plot\n", "g.ax_marg_x.annotate(description, xy=(0.015, -0.01), size=6, xycoords='figure fraction', c=snark_palette[-1])\n", "g.ax_joint.set_xlabel('Happiness score', loc='center', size='x-large', c=snark_palette[-1]) # set label of x axis\n", "g.ax_joint.set_ylabel('Infant mortality rate', loc='center', size='x-large', c=snark_palette[-1]) # set label of x axis\n", "g.ax_joint.tick_params(axis='both', labelsize='large', colors=snark_palette[-1]) # set x/y ticks\n", "g.ax_joint.spines['bottom'].set_color(snark_palette[-1]) # color x axis\n", "g.ax_joint.spines['left'].set_color(snark_palette[-1]) # color y axis\n", "g.ax_marg_x.tick_params(axis='x', bottom=False) # disable x margin ticks\n", "g.ax_marg_x.spines['bottom'].set_color(snark_palette[0])\n", "g.ax_marg_y.tick_params(axis='y', left=False) # disable y margin ticks\n", "g.ax_marg_y.spines['left'].set_color(snark_palette[0])\n", "\n", "# Save and plot\n", "plt.savefig('plot.pic/plot.happiness.health.infant_mortality.png', dpi=150, bbox_inches='tight')\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Total Fertility Rate And Obesity Rate" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "\r\n", "\r\n", "\r\n", "\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " 2020-10-13T22:34:32.996897\r\n", " image/svg+xml\r\n", " \r\n", " \r\n", " Matplotlib v3.3.1, https://matplotlib.org/\r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", " \r\n", "\r\n" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Inscriptions\n", "title = \"\"\"The Relationship Between Total Fertility And Obesity\"\"\"\n", "description = \"\"\"\n", "Correlation of the total fertility rate with the obesity rate by country based on 2016 data.\n", "Data: Gallup World Poll - www.kaggle.com/unsdsn/world-happiness & CIA - www.cia.gov/library/publications/the-world-factbook | Author: @data.sugar\n", "\"\"\"\n", "\n", "# Plot size\n", "figsize = (6,4)\n", "\n", "# Set the figure\n", "sns.set(context='paper', style='ticks', palette=snark_palette,\n", " rc={'xtick.major.size': 4, 'ytick.major.size':4,\n", " 'axes.spines.left': False, 'axes.spines.bottom': False,\n", " 'axes.spines.right': False, 'axes.spines.top': False\n", " }\n", " )\n", "\n", "# Create the plot\n", "fig = plt.figure(figsize=figsize, facecolor='w')\n", "g = sns.jointplot(x='obesity', y='tfr', data=happiness_cia,\n", " kind='reg', truncate=False, dropna=True,\n", " xlim=(0, 40), ylim=(0, 7),\n", " marginal_kws=dict(hist=True, bins=10),\n", " color=snark_palette[0]\n", " )\n", "\n", "# Set some aesthetic params for the plot\n", "g.ax_marg_x.set_title(title, fontdict={'fontsize': 16}, loc='center', pad=10, c=snark_palette[-1]) # set a title of the plot\n", "g.ax_marg_x.annotate(description, xy=(0.015, -0.01), size=6, xycoords='figure fraction', c=snark_palette[-1])\n", "g.ax_joint.set_xlabel('Obesity rate', loc='center', size='x-large', c=snark_palette[-1]) # set label of x axis\n", "g.ax_joint.set_ylabel('Total fertility rate', loc='center', size='x-large', c=snark_palette[-1]) # set label of x axis\n", "g.ax_joint.tick_params(axis='both', labelsize='large', colors=snark_palette[-1]) # set x/y ticks\n", "g.ax_joint.spines['bottom'].set_color(snark_palette[-1]) # color x axis\n", "g.ax_joint.spines['left'].set_color(snark_palette[-1]) # color y axis\n", "g.ax_marg_x.tick_params(axis='x', bottom=False) # disable x margin ticks\n", "g.ax_marg_x.spines['bottom'].set_color(snark_palette[0])\n", "g.ax_marg_y.tick_params(axis='y', left=False) # disable y margin ticks\n", "g.ax_marg_y.spines['left'].set_color(snark_palette[0])\n", "\n", "# Save and plot\n", "plt.savefig('plot.pic/plot.happiness.health.tfr_obesity.png', dpi=150, bbox_inches='tight')\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Conclusions\n", "\n", "As we mentioned above, there is no significant correlation between the HIV/AIDS rates and the happiness score.\n", "\n", "And these correlations are quite high (above 0.8):\n", "\n", "- total fertility rate and infant mortality rate;\n", "- maternal mortality rate and infant mortality rate;\n", "- maternal mortality rate and total fertility rate.\n", "\n", "And it seems natural. If the birth rate per woman is higher, the risk of maternal and infant mortality is higher, given the fact that total fertility, maternal mortality, and infant mortality are inversely proportional to the level of happiness. In other words, the birth rate, maternal and infant mortality are higher in the least happy countries. \n", "\n", "Statistics do not give the root cause: people are happy, and therefore infant mortality is lower, or mortality is lower, and therefore people are happier (because they are generally healthier). Which came first - the chicken or the egg. \n", "\n", "There is a low negative correlation between the total fertility rate and the obesity rate. \n", "What does it mean? Does this mean that satisfied people don't want to think about procreation?\n", "\n", "What about happiness? \n", "The higher a country is on the happiness stairs, the higher the obesity rate, but the lower the total fertility, as well as maternal and infant mortality.\n", "\n", "\n", "# Blog Post" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1935" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "blog_post = r\"\"\"\n", "## IN SEARCH OF 🎈HAPPINESS: 🍔WHAT if HEALTH? \n", "\n", "\n", "💪We continue our happiness #challenge! \n", "\n", "👀And now we wonder whether high \\#health indicators contribute to \\#happiness.\n", "To compare health indicators with happiness score, we'll take the World Happiness Report from \\#Kaggle, which ranks 156 countries for happiness on a 10-point scale, and use \\#CIA data from The World Factbook.\n", "\n", "📌Today we would like to know how health makes us happy! \n", "\n", "✔The correlation map we built says that the more food, the more happiness (see the relationship between obesity and happiness). \n", "Oh, we already knew that, a hungry man is an angry man.\n", "\n", "✔Surprisingly, there is no correlation between HIV/AIDS rates and the level of happiness we expected.\n", "\n", "✔There is a low negative correlation between the total fertility rate and the obesity rate.\n", "What does it mean? Does this mean that satisfied people don't want to think about procreation?\n", "\n", "✔If the birth rate per woman is higher, the risk of maternal and infant mortality is higher, given the fact that total fertility, maternal mortality and infant mortality are inversely proportional to the level of happiness. \n", "In other words, the birth rate, maternal and infant mortality are higher in the least happy countries.\n", "\n", "Statistics don't give the root cause: people are happy, and therefore infant mortality is lower, or mortality is lower, and therefore people are happier (because they are generally healthier). \n", "Which came first - the chicken or the egg.\n", "\n", "📝What about happiness? \n", "The higher a country is on the happiness stairs, the higher the obesity rate, but the lower the total fertility, as well as maternal and infant mortality.\n", "\n", "#tobecontinued\n", "\n", "(Interested in more details? Follow the link in bio for the entire research project!) \n", ". \n", ". \n", ". \n", "\\#funtime \\#probably \\#datascience \\#datapower \\#data_sugar_happiness \\#happy\n", "\\#data_know_everything_and_nothing \\#linkinbio \\#datajournalism \\#python\n", "\"\"\"\n", "\n", "# Check post text length for Instagram\n", "len(blog_post)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "\n", "## IN SEARCH OF 🎈HAPPINESS: 🍔WHAT if HEALTH? \n", "\n", "\n", "💪We continue our happiness #challenge! \n", "\n", "👀And now we wonder whether high \\#health indicators contribute to \\#happiness.\n", "To compare health indicators with happiness score, we'll take the World Happiness Report from \\#Kaggle, which ranks 156 countries for happiness on a 10-point scale, and use \\#CIA data from The World Factbook.\n", "\n", "📌Today we would like to know how health makes us happy! \n", "\n", "✔The correlation map we built says that the more food, the more happiness (see the relationship between obesity and happiness). \n", "Oh, we already knew that, a hungry man is an angry man.\n", "\n", "✔Surprisingly, there is no correlation between HIV/AIDS rates and the level of happiness we expected.\n", "\n", "✔There is a low negative correlation between the total fertility rate and the obesity rate.\n", "What does it mean? Does this mean that satisfied people don't want to think about procreation?\n", "\n", "✔If the birth rate per woman is higher, the risk of maternal and infant mortality is higher, given the fact that total fertility, maternal mortality and infant mortality are inversely proportional to the level of happiness. \n", "In other words, the birth rate, maternal and infant mortality are higher in the least happy countries.\n", "\n", "Statistics don't give the root cause: people are happy, and therefore infant mortality is lower, or mortality is lower, and therefore people are happier (because they are generally healthier). \n", "Which came first - the chicken or the egg.\n", "\n", "📝What about happiness? \n", "The higher a country is on the happiness stairs, the higher the obesity rate, but the lower the total fertility, as well as maternal and infant mortality.\n", "\n", "#tobecontinued\n", "\n", "(Interested in more details? Follow the link in bio for the entire research project!) \n", ". \n", ". \n", ". \n", "\\#funtime \\#probably \\#datascience \\#datapower \\#data_sugar_happiness \\#happy\n", "\\#data_know_everything_and_nothing \\#linkinbio \\#datajournalism \\#python\n" ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from IPython.display import Markdown as md\n", "md(blog_post)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.1" } }, "nbformat": 4, "nbformat_minor": 4 }