208 lines
5.5 KiB
Plaintext
208 lines
5.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"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": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"---"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Reading and preprocessing data"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"DataWhr2024 = pd.read_csv(\"DataWhr2024.csv\")\n",
|
|
"UnM49 = pd.read_csv(\"UnM49.csv\", sep=';')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"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": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"DataWhr2024.loc[DataWhr2024[\"Country name\"].str.startswith(\"Hong\"), \"Country name\"] = \"Hong Kong\"\n",
|
|
"DataWhr2024.loc[DataWhr2024[\"Country name\"].str.startswith(\"Somaliland\"), \"Country name\"] = \"Somaliland\"\n",
|
|
"DataWhr2024.loc[DataWhr2024[\"Country name\"].str.startswith(\"Taiwan\"), \"Country name\"] = \"Taiwan\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"UnM49.loc[97, \"Country name\"] = \"Bolivia\"\n",
|
|
"UnM49.loc[33, \"Country name\"] = \"Congo (Brazzaville)\"\n",
|
|
"UnM49.loc[34, \"Country name\"] = \"Congo (Kinshasa)\"\n",
|
|
"UnM49.loc[124, \"Country name\"] = \"Hong Kong\"\n",
|
|
"UnM49.loc[125, \"Country name\"] = \"Macao\"\n",
|
|
"UnM49.loc[126, \"Country name\"] = \"North Korea\"\n",
|
|
"UnM49.loc[145, \"Country name\"] = \"Iran\"\n",
|
|
"UnM49.loc[46, \"Country name\"] = \"Ivory Coast\"\n",
|
|
"UnM49.loc[133, \"Country name\"] = \"Laos\"\n",
|
|
"UnM49.loc[129, \"Country name\"] = \"South Korea\"\n",
|
|
"UnM49.loc[173, \"Country name\"] = \"Moldova\"\n",
|
|
"UnM49.loc[217, \"Country name\"] = \"Netherlands\"\n",
|
|
"UnM49.loc[175, \"Country name\"] = \"Russia\"\n",
|
|
"UnM49.loc[164, \"Country name\"] = \"Syria\"\n",
|
|
"UnM49.loc[26, \"Country name\"] = \"Tanzania\"\n",
|
|
"UnM49.loc[116, \"Country name\"] = \"United States\"\n",
|
|
"UnM49.loc[193, \"Country name\"] = \"United Kingdom\"\n",
|
|
"UnM49.loc[111, \"Country name\"] = \"Venezuela\"\n",
|
|
"UnM49.loc[140, \"Country name\"] = \"Vietnam\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"_ = pd.DataFrame(\n",
|
|
" {\n",
|
|
" \"Country name\": [\"Kosovo\", \"Somaliland\", \"Taiwan\"],\n",
|
|
" \"Subregion\": [\"Southern Europe\", \"Sub-Saharan Africa\", \"Eastern Asia\"],\n",
|
|
" \"Continent\": [\"Europe\", \"Africa\", \"Asia\"],\n",
|
|
" }\n",
|
|
")\n",
|
|
"\n",
|
|
"UnM49 = pd.concat([UnM49, _], axis=0)\n",
|
|
"UnM49 = UnM49.reset_index(drop=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"---"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Data\n",
|
|
"Dat = pd.merge(DataWhr2024, UnM49)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Data of 2023\n",
|
|
"Dat2023 = Dat[Dat['year'] == 2023]\n",
|
|
"Dat2023 = Dat2023.reset_index(drop=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"['Iceland',\n",
|
|
" 'India',\n",
|
|
" 'Indonesia',\n",
|
|
" 'Iran',\n",
|
|
" 'Iraq',\n",
|
|
" 'Ireland',\n",
|
|
" 'Israel',\n",
|
|
" 'Italy',\n",
|
|
" 'Ivory Coast']"
|
|
]
|
|
},
|
|
"execution_count": 9,
|
|
"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": 10,
|
|
"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)"
|
|
]
|
|
}
|
|
],
|
|
"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.5"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|