877 lines
28 KiB
Plaintext
877 lines
28 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 21,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"import numpy as np\n",
|
|||
|
"import pandas as pd\n",
|
|||
|
"import seaborn as sns\n",
|
|||
|
"import matplotlib.pyplot as plt\n",
|
|||
|
"\n",
|
|||
|
"# Gamma function\n",
|
|||
|
"from scipy.special import gamma\n",
|
|||
|
"\n",
|
|||
|
"# To calculate statistics\n",
|
|||
|
"from scipy.stats import norm\n",
|
|||
|
"from scipy.stats import hmean, trim_mean, iqr, median_abs_deviation, skew, kurtosis\n",
|
|||
|
"from scipy.stats.mstats import gmean, winsorize"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 22,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"DataWhr2024 = pd.read_csv(\"../DataWhr2024.csv\")\n",
|
|||
|
"UnM49 = pd.read_csv(\"./UnM49.csv\", sep=';')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 23,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"UnM49 = UnM49[['Country or Area', 'Sub-region Name', 'Region Name']]\n",
|
|||
|
"UnM49 = UnM49.rename({'Country or Area':'Country name', 'Sub-region Name':'Subregion', 'Region Name':'Continent'}, axis=1)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"---"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 24,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"# Data\n",
|
|||
|
"Dat = pd.merge(DataWhr2024, UnM49)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 25,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"# Data of 2023\n",
|
|||
|
"Dat2023 = Dat[Dat['year'] == 2023]\n",
|
|||
|
"Dat2023 = Dat2023.reset_index(drop=True)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 26,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"['Iceland', 'India', 'Indonesia', 'Iraq', 'Ireland', 'Israel', 'Italy']"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 26,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"# Countries that starts with the same letter that your name\n",
|
|||
|
"StartsWith = 'I' # The first letter of your name\n",
|
|||
|
"list(Dat[Dat['Country name'].str.startswith(StartsWith)]['Country name'].unique())"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 27,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"# Data of 2023 from the region selected\n",
|
|||
|
"CountrySelected = 'Iraq' # Change to the country that you selected\n",
|
|||
|
"SubregionSelected = Dat[Dat['Country name']==CountrySelected]['Subregion'].unique()[0]\n",
|
|||
|
"\n",
|
|||
|
"DatSelected = Dat2023[Dat2023['Subregion']==SubregionSelected]\n",
|
|||
|
"DatSelected = DatSelected.reset_index(drop=True)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 28,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>year</th>\n",
|
|||
|
" <th>Life Ladder</th>\n",
|
|||
|
" <th>Log GDP per capita</th>\n",
|
|||
|
" <th>Social support</th>\n",
|
|||
|
" <th>Healthy life expectancy at birth</th>\n",
|
|||
|
" <th>Freedom to make life choices</th>\n",
|
|||
|
" <th>Generosity</th>\n",
|
|||
|
" <th>Perceptions of corruption</th>\n",
|
|||
|
" <th>Positive affect</th>\n",
|
|||
|
" <th>Negative affect</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>count</th>\n",
|
|||
|
" <td>121.0</td>\n",
|
|||
|
" <td>121.000000</td>\n",
|
|||
|
" <td>114.000000</td>\n",
|
|||
|
" <td>121.000000</td>\n",
|
|||
|
" <td>120.000000</td>\n",
|
|||
|
" <td>119.000000</td>\n",
|
|||
|
" <td>114.000000</td>\n",
|
|||
|
" <td>114.000000</td>\n",
|
|||
|
" <td>121.000000</td>\n",
|
|||
|
" <td>121.000000</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>mean</th>\n",
|
|||
|
" <td>2023.0</td>\n",
|
|||
|
" <td>5.601455</td>\n",
|
|||
|
" <td>9.527377</td>\n",
|
|||
|
" <td>0.792537</td>\n",
|
|||
|
" <td>65.283333</td>\n",
|
|||
|
" <td>0.789227</td>\n",
|
|||
|
" <td>0.027851</td>\n",
|
|||
|
" <td>0.722447</td>\n",
|
|||
|
" <td>0.650488</td>\n",
|
|||
|
" <td>0.295818</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>std</th>\n",
|
|||
|
" <td>0.0</td>\n",
|
|||
|
" <td>1.159381</td>\n",
|
|||
|
" <td>1.151462</td>\n",
|
|||
|
" <td>0.131982</td>\n",
|
|||
|
" <td>5.580870</td>\n",
|
|||
|
" <td>0.124732</td>\n",
|
|||
|
" <td>0.162959</td>\n",
|
|||
|
" <td>0.182586</td>\n",
|
|||
|
" <td>0.113365</td>\n",
|
|||
|
" <td>0.085531</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>min</th>\n",
|
|||
|
" <td>2023.0</td>\n",
|
|||
|
" <td>1.446000</td>\n",
|
|||
|
" <td>7.147000</td>\n",
|
|||
|
" <td>0.368000</td>\n",
|
|||
|
" <td>52.200000</td>\n",
|
|||
|
" <td>0.228000</td>\n",
|
|||
|
" <td>-0.268000</td>\n",
|
|||
|
" <td>0.153000</td>\n",
|
|||
|
" <td>0.261000</td>\n",
|
|||
|
" <td>0.114000</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>25%</th>\n",
|
|||
|
" <td>2023.0</td>\n",
|
|||
|
" <td>4.609000</td>\n",
|
|||
|
" <td>8.612500</td>\n",
|
|||
|
" <td>0.703000</td>\n",
|
|||
|
" <td>60.700000</td>\n",
|
|||
|
" <td>0.734500</td>\n",
|
|||
|
" <td>-0.088750</td>\n",
|
|||
|
" <td>0.663250</td>\n",
|
|||
|
" <td>0.579000</td>\n",
|
|||
|
" <td>0.231000</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>50%</th>\n",
|
|||
|
" <td>2023.0</td>\n",
|
|||
|
" <td>5.868000</td>\n",
|
|||
|
" <td>9.670000</td>\n",
|
|||
|
" <td>0.831000</td>\n",
|
|||
|
" <td>66.300000</td>\n",
|
|||
|
" <td>0.807000</td>\n",
|
|||
|
" <td>0.022000</td>\n",
|
|||
|
" <td>0.781000</td>\n",
|
|||
|
" <td>0.661000</td>\n",
|
|||
|
" <td>0.289000</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>75%</th>\n",
|
|||
|
" <td>2023.0</td>\n",
|
|||
|
" <td>6.482000</td>\n",
|
|||
|
" <td>10.496250</td>\n",
|
|||
|
" <td>0.895000</td>\n",
|
|||
|
" <td>69.775000</td>\n",
|
|||
|
" <td>0.877000</td>\n",
|
|||
|
" <td>0.122500</td>\n",
|
|||
|
" <td>0.844500</td>\n",
|
|||
|
" <td>0.738000</td>\n",
|
|||
|
" <td>0.358000</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>max</th>\n",
|
|||
|
" <td>2023.0</td>\n",
|
|||
|
" <td>7.699000</td>\n",
|
|||
|
" <td>11.676000</td>\n",
|
|||
|
" <td>0.979000</td>\n",
|
|||
|
" <td>74.600000</td>\n",
|
|||
|
" <td>0.965000</td>\n",
|
|||
|
" <td>0.590000</td>\n",
|
|||
|
" <td>0.948000</td>\n",
|
|||
|
" <td>0.843000</td>\n",
|
|||
|
" <td>0.516000</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" year Life Ladder Log GDP per capita Social support \\\n",
|
|||
|
"count 121.0 121.000000 114.000000 121.000000 \n",
|
|||
|
"mean 2023.0 5.601455 9.527377 0.792537 \n",
|
|||
|
"std 0.0 1.159381 1.151462 0.131982 \n",
|
|||
|
"min 2023.0 1.446000 7.147000 0.368000 \n",
|
|||
|
"25% 2023.0 4.609000 8.612500 0.703000 \n",
|
|||
|
"50% 2023.0 5.868000 9.670000 0.831000 \n",
|
|||
|
"75% 2023.0 6.482000 10.496250 0.895000 \n",
|
|||
|
"max 2023.0 7.699000 11.676000 0.979000 \n",
|
|||
|
"\n",
|
|||
|
" Healthy life expectancy at birth Freedom to make life choices \\\n",
|
|||
|
"count 120.000000 119.000000 \n",
|
|||
|
"mean 65.283333 0.789227 \n",
|
|||
|
"std 5.580870 0.124732 \n",
|
|||
|
"min 52.200000 0.228000 \n",
|
|||
|
"25% 60.700000 0.734500 \n",
|
|||
|
"50% 66.300000 0.807000 \n",
|
|||
|
"75% 69.775000 0.877000 \n",
|
|||
|
"max 74.600000 0.965000 \n",
|
|||
|
"\n",
|
|||
|
" Generosity Perceptions of corruption Positive affect Negative affect \n",
|
|||
|
"count 114.000000 114.000000 121.000000 121.000000 \n",
|
|||
|
"mean 0.027851 0.722447 0.650488 0.295818 \n",
|
|||
|
"std 0.162959 0.182586 0.113365 0.085531 \n",
|
|||
|
"min -0.268000 0.153000 0.261000 0.114000 \n",
|
|||
|
"25% -0.088750 0.663250 0.579000 0.231000 \n",
|
|||
|
"50% 0.022000 0.781000 0.661000 0.289000 \n",
|
|||
|
"75% 0.122500 0.844500 0.738000 0.358000 \n",
|
|||
|
"max 0.590000 0.948000 0.843000 0.516000 "
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 28,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"Dat2023.describe()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 29,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>Country name</th>\n",
|
|||
|
" <th>year</th>\n",
|
|||
|
" <th>Life Ladder</th>\n",
|
|||
|
" <th>Log GDP per capita</th>\n",
|
|||
|
" <th>Social support</th>\n",
|
|||
|
" <th>Healthy life expectancy at birth</th>\n",
|
|||
|
" <th>Freedom to make life choices</th>\n",
|
|||
|
" <th>Generosity</th>\n",
|
|||
|
" <th>Perceptions of corruption</th>\n",
|
|||
|
" <th>Positive affect</th>\n",
|
|||
|
" <th>Negative affect</th>\n",
|
|||
|
" <th>Subregion</th>\n",
|
|||
|
" <th>Continent</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>Afghanistan</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>1.446</td>\n",
|
|||
|
" <td>NaN</td>\n",
|
|||
|
" <td>0.368</td>\n",
|
|||
|
" <td>55.2</td>\n",
|
|||
|
" <td>0.228</td>\n",
|
|||
|
" <td>NaN</td>\n",
|
|||
|
" <td>0.738</td>\n",
|
|||
|
" <td>0.261</td>\n",
|
|||
|
" <td>0.460</td>\n",
|
|||
|
" <td>Southern Asia</td>\n",
|
|||
|
" <td>Asia</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>Albania</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>5.445</td>\n",
|
|||
|
" <td>9.689</td>\n",
|
|||
|
" <td>0.691</td>\n",
|
|||
|
" <td>69.2</td>\n",
|
|||
|
" <td>0.872</td>\n",
|
|||
|
" <td>0.068</td>\n",
|
|||
|
" <td>0.855</td>\n",
|
|||
|
" <td>0.597</td>\n",
|
|||
|
" <td>0.314</td>\n",
|
|||
|
" <td>Southern Europe</td>\n",
|
|||
|
" <td>Europe</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>Argentina</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>6.393</td>\n",
|
|||
|
" <td>9.994</td>\n",
|
|||
|
" <td>0.892</td>\n",
|
|||
|
" <td>67.3</td>\n",
|
|||
|
" <td>0.832</td>\n",
|
|||
|
" <td>-0.129</td>\n",
|
|||
|
" <td>0.846</td>\n",
|
|||
|
" <td>0.720</td>\n",
|
|||
|
" <td>0.301</td>\n",
|
|||
|
" <td>Latin America and the Caribbean</td>\n",
|
|||
|
" <td>Americas</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>Armenia</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>5.679</td>\n",
|
|||
|
" <td>9.730</td>\n",
|
|||
|
" <td>0.819</td>\n",
|
|||
|
" <td>68.2</td>\n",
|
|||
|
" <td>0.819</td>\n",
|
|||
|
" <td>-0.179</td>\n",
|
|||
|
" <td>0.681</td>\n",
|
|||
|
" <td>0.575</td>\n",
|
|||
|
" <td>0.423</td>\n",
|
|||
|
" <td>Western Asia</td>\n",
|
|||
|
" <td>Asia</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>Australia</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>7.025</td>\n",
|
|||
|
" <td>10.846</td>\n",
|
|||
|
" <td>0.896</td>\n",
|
|||
|
" <td>71.2</td>\n",
|
|||
|
" <td>0.876</td>\n",
|
|||
|
" <td>0.187</td>\n",
|
|||
|
" <td>0.482</td>\n",
|
|||
|
" <td>0.731</td>\n",
|
|||
|
" <td>0.248</td>\n",
|
|||
|
" <td>Australia and New Zealand</td>\n",
|
|||
|
" <td>Oceania</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>...</th>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" <td>...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>116</th>\n",
|
|||
|
" <td>Uruguay</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>6.662</td>\n",
|
|||
|
" <td>10.122</td>\n",
|
|||
|
" <td>0.908</td>\n",
|
|||
|
" <td>67.5</td>\n",
|
|||
|
" <td>0.904</td>\n",
|
|||
|
" <td>-0.050</td>\n",
|
|||
|
" <td>0.662</td>\n",
|
|||
|
" <td>0.753</td>\n",
|
|||
|
" <td>0.265</td>\n",
|
|||
|
" <td>Latin America and the Caribbean</td>\n",
|
|||
|
" <td>Americas</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>117</th>\n",
|
|||
|
" <td>Uzbekistan</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>6.385</td>\n",
|
|||
|
" <td>9.026</td>\n",
|
|||
|
" <td>0.909</td>\n",
|
|||
|
" <td>65.9</td>\n",
|
|||
|
" <td>0.927</td>\n",
|
|||
|
" <td>0.247</td>\n",
|
|||
|
" <td>0.650</td>\n",
|
|||
|
" <td>0.752</td>\n",
|
|||
|
" <td>0.202</td>\n",
|
|||
|
" <td>Central Asia</td>\n",
|
|||
|
" <td>Asia</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>118</th>\n",
|
|||
|
" <td>Yemen</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>3.532</td>\n",
|
|||
|
" <td>NaN</td>\n",
|
|||
|
" <td>0.825</td>\n",
|
|||
|
" <td>56.6</td>\n",
|
|||
|
" <td>0.583</td>\n",
|
|||
|
" <td>NaN</td>\n",
|
|||
|
" <td>0.771</td>\n",
|
|||
|
" <td>0.447</td>\n",
|
|||
|
" <td>0.341</td>\n",
|
|||
|
" <td>Western Asia</td>\n",
|
|||
|
" <td>Asia</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>119</th>\n",
|
|||
|
" <td>Zambia</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>3.686</td>\n",
|
|||
|
" <td>8.115</td>\n",
|
|||
|
" <td>0.664</td>\n",
|
|||
|
" <td>56.1</td>\n",
|
|||
|
" <td>0.854</td>\n",
|
|||
|
" <td>0.092</td>\n",
|
|||
|
" <td>0.814</td>\n",
|
|||
|
" <td>0.653</td>\n",
|
|||
|
" <td>0.359</td>\n",
|
|||
|
" <td>Sub-Saharan Africa</td>\n",
|
|||
|
" <td>Africa</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>120</th>\n",
|
|||
|
" <td>Zimbabwe</td>\n",
|
|||
|
" <td>2023</td>\n",
|
|||
|
" <td>3.572</td>\n",
|
|||
|
" <td>7.679</td>\n",
|
|||
|
" <td>0.694</td>\n",
|
|||
|
" <td>55.0</td>\n",
|
|||
|
" <td>0.735</td>\n",
|
|||
|
" <td>-0.069</td>\n",
|
|||
|
" <td>0.757</td>\n",
|
|||
|
" <td>0.610</td>\n",
|
|||
|
" <td>0.179</td>\n",
|
|||
|
" <td>Sub-Saharan Africa</td>\n",
|
|||
|
" <td>Africa</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"<p>121 rows × 13 columns</p>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" Country name year Life Ladder Log GDP per capita Social support \\\n",
|
|||
|
"0 Afghanistan 2023 1.446 NaN 0.368 \n",
|
|||
|
"1 Albania 2023 5.445 9.689 0.691 \n",
|
|||
|
"2 Argentina 2023 6.393 9.994 0.892 \n",
|
|||
|
"3 Armenia 2023 5.679 9.730 0.819 \n",
|
|||
|
"4 Australia 2023 7.025 10.846 0.896 \n",
|
|||
|
".. ... ... ... ... ... \n",
|
|||
|
"116 Uruguay 2023 6.662 10.122 0.908 \n",
|
|||
|
"117 Uzbekistan 2023 6.385 9.026 0.909 \n",
|
|||
|
"118 Yemen 2023 3.532 NaN 0.825 \n",
|
|||
|
"119 Zambia 2023 3.686 8.115 0.664 \n",
|
|||
|
"120 Zimbabwe 2023 3.572 7.679 0.694 \n",
|
|||
|
"\n",
|
|||
|
" Healthy life expectancy at birth Freedom to make life choices \\\n",
|
|||
|
"0 55.2 0.228 \n",
|
|||
|
"1 69.2 0.872 \n",
|
|||
|
"2 67.3 0.832 \n",
|
|||
|
"3 68.2 0.819 \n",
|
|||
|
"4 71.2 0.876 \n",
|
|||
|
".. ... ... \n",
|
|||
|
"116 67.5 0.904 \n",
|
|||
|
"117 65.9 0.927 \n",
|
|||
|
"118 56.6 0.583 \n",
|
|||
|
"119 56.1 0.854 \n",
|
|||
|
"120 55.0 0.735 \n",
|
|||
|
"\n",
|
|||
|
" Generosity Perceptions of corruption Positive affect Negative affect \\\n",
|
|||
|
"0 NaN 0.738 0.261 0.460 \n",
|
|||
|
"1 0.068 0.855 0.597 0.314 \n",
|
|||
|
"2 -0.129 0.846 0.720 0.301 \n",
|
|||
|
"3 -0.179 0.681 0.575 0.423 \n",
|
|||
|
"4 0.187 0.482 0.731 0.248 \n",
|
|||
|
".. ... ... ... ... \n",
|
|||
|
"116 -0.050 0.662 0.753 0.265 \n",
|
|||
|
"117 0.247 0.650 0.752 0.202 \n",
|
|||
|
"118 NaN 0.771 0.447 0.341 \n",
|
|||
|
"119 0.092 0.814 0.653 0.359 \n",
|
|||
|
"120 -0.069 0.757 0.610 0.179 \n",
|
|||
|
"\n",
|
|||
|
" Subregion Continent \n",
|
|||
|
"0 Southern Asia Asia \n",
|
|||
|
"1 Southern Europe Europe \n",
|
|||
|
"2 Latin America and the Caribbean Americas \n",
|
|||
|
"3 Western Asia Asia \n",
|
|||
|
"4 Australia and New Zealand Oceania \n",
|
|||
|
".. ... ... \n",
|
|||
|
"116 Latin America and the Caribbean Americas \n",
|
|||
|
"117 Central Asia Asia \n",
|
|||
|
"118 Western Asia Asia \n",
|
|||
|
"119 Sub-Saharan Africa Africa \n",
|
|||
|
"120 Sub-Saharan Africa Africa \n",
|
|||
|
"\n",
|
|||
|
"[121 rows x 13 columns]"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 29,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"Dat2023"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 40,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>Country name</th>\n",
|
|||
|
" <th>year</th>\n",
|
|||
|
" <th>Life Ladder</th>\n",
|
|||
|
" <th>Log GDP per capita</th>\n",
|
|||
|
" <th>Social support</th>\n",
|
|||
|
" <th>Healthy life expectancy at birth</th>\n",
|
|||
|
" <th>Freedom to make life choices</th>\n",
|
|||
|
" <th>Generosity</th>\n",
|
|||
|
" <th>Perceptions of corruption</th>\n",
|
|||
|
" <th>Positive affect</th>\n",
|
|||
|
" <th>Negative affect</th>\n",
|
|||
|
" <th>Subregion</th>\n",
|
|||
|
" <th>Continent</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>13</th>\n",
|
|||
|
" <td>Afghanistan</td>\n",
|
|||
|
" <td>2022</td>\n",
|
|||
|
" <td>1.281</td>\n",
|
|||
|
" <td>NaN</td>\n",
|
|||
|
" <td>0.228</td>\n",
|
|||
|
" <td>54.875</td>\n",
|
|||
|
" <td>0.368</td>\n",
|
|||
|
" <td>NaN</td>\n",
|
|||
|
" <td>0.733</td>\n",
|
|||
|
" <td>0.206</td>\n",
|
|||
|
" <td>0.576</td>\n",
|
|||
|
" <td>Southern Asia</td>\n",
|
|||
|
" <td>Asia</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" Country name year Life Ladder Log GDP per capita Social support \\\n",
|
|||
|
"13 Afghanistan 2022 1.281 NaN 0.228 \n",
|
|||
|
"\n",
|
|||
|
" Healthy life expectancy at birth Freedom to make life choices \\\n",
|
|||
|
"13 54.875 0.368 \n",
|
|||
|
"\n",
|
|||
|
" Generosity Perceptions of corruption Positive affect Negative affect \\\n",
|
|||
|
"13 NaN 0.733 0.206 0.576 \n",
|
|||
|
"\n",
|
|||
|
" Subregion Continent \n",
|
|||
|
"13 Southern Asia Asia "
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 40,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"Dat.loc[Dat[\"Life Ladder\"] == Dat[\"Life Ladder\"].min()]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 43,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style scoped>\n",
|
|||
|
" .dataframe tbody tr th:only-of-type {\n",
|
|||
|
" vertical-align: middle;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>Country name</th>\n",
|
|||
|
" <th>year</th>\n",
|
|||
|
" <th>Life Ladder</th>\n",
|
|||
|
" <th>Log GDP per capita</th>\n",
|
|||
|
" <th>Social support</th>\n",
|
|||
|
" <th>Healthy life expectancy at birth</th>\n",
|
|||
|
" <th>Freedom to make life choices</th>\n",
|
|||
|
" <th>Generosity</th>\n",
|
|||
|
" <th>Perceptions of corruption</th>\n",
|
|||
|
" <th>Positive affect</th>\n",
|
|||
|
" <th>Negative affect</th>\n",
|
|||
|
" <th>Subregion</th>\n",
|
|||
|
" <th>Continent</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>497</th>\n",
|
|||
|
" <td>Denmark</td>\n",
|
|||
|
" <td>2005</td>\n",
|
|||
|
" <td>8.019</td>\n",
|
|||
|
" <td>10.849</td>\n",
|
|||
|
" <td>0.972</td>\n",
|
|||
|
" <td>68.3</td>\n",
|
|||
|
" <td>0.971</td>\n",
|
|||
|
" <td>NaN</td>\n",
|
|||
|
" <td>0.237</td>\n",
|
|||
|
" <td>0.777</td>\n",
|
|||
|
" <td>0.154</td>\n",
|
|||
|
" <td>Northern Europe</td>\n",
|
|||
|
" <td>Europe</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" Country name year Life Ladder Log GDP per capita Social support \\\n",
|
|||
|
"497 Denmark 2005 8.019 10.849 0.972 \n",
|
|||
|
"\n",
|
|||
|
" Healthy life expectancy at birth Freedom to make life choices \\\n",
|
|||
|
"497 68.3 0.971 \n",
|
|||
|
"\n",
|
|||
|
" Generosity Perceptions of corruption Positive affect Negative affect \\\n",
|
|||
|
"497 NaN 0.237 0.777 0.154 \n",
|
|||
|
"\n",
|
|||
|
" Subregion Continent \n",
|
|||
|
"497 Northern Europe Europe "
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 43,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"Dat.loc[Dat[\"Life Ladder\"] == Dat[\"Life Ladder\"].max()]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 48,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"avg_health = Dat[\"Healthy life expectancy at birth\"].median()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 50,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"65.22\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"print(avg_health)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 56,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"np.float64(0.231)"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 56,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"#p = [0.25, 0.5, 0.75]\n",
|
|||
|
"np.quantile(Dat2023[\"Negative affect\"], 0.25)\n",
|
|||
|
"\n",
|
|||
|
"#Dat[\"Negative affect\"]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 57,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"array([4.6125, 5.42 , 6.3215])"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 57,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"p = [0.25, 0.5, 0.75]\n",
|
|||
|
"np.quantile(Dat[\"Life Ladder\"], p)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 64,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"5.42\n",
|
|||
|
"5.4660082404265635\n",
|
|||
|
"5.3416056329049155\n",
|
|||
|
"5.207292342092034\n",
|
|||
|
"5.446561471442401\n",
|
|||
|
"1.7089999999999996\n",
|
|||
|
"5.4660082404265635\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"ll = Dat[\"Life Ladder\"]\n",
|
|||
|
"\n",
|
|||
|
"print(ll.median())\n",
|
|||
|
"print(ll.mean())\n",
|
|||
|
"print(gmean(ll))\n",
|
|||
|
"print(hmean(ll))\n",
|
|||
|
"print(trim_mean(ll, 0.25))\n",
|
|||
|
"print(iqr(ll).mean())\n",
|
|||
|
"print(winsorize(ll).mean())"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"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.12.6"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 2
|
|||
|
}
|