text_html_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

life = pd.read_csv('/kaggle/input/life-expectancy-who-updated/Life-Expectancy-Data-Updated.csv')

life[['Adult_mortality', 'Infant_deaths', 'Under_five_deaths']] = life[['Adult_mortality', 'Infant_deaths', 'Under_five_deaths']] / 10

groupyears = life.groupby('Year')['Country'].value_counts()
groupyears = groupyears.unstack()
missing_country = []
for index, rows in groupyears.iterrows():
    for col in groupyears.columns:
        if groupyears.loc[index, col] != 1:
            missing_country.append([index, col])
        else:
            None

average_timeline = life.groupby('Year')['Life_expectancy'].mean()
average_compare = life[life['Year'].isin([2000, 2015])].groupby(['Year', 'Region', 'Country'])['Life_expectancy'].median()

average_timeline = life.groupby('Year')['Life_expectancy'].mean()
average_compare = life[life['Year'].isin([2000, 2015])].groupby(['Year', 'Region', 'Country'])['Life_expectancy'].median()

sns.kdeplot(data=life[life['Year'].isin([2000, 2015])], x='Life_expectancy', hue='Year', fill=True, palette=sns.color_palette('BrBG', 2))
plt.axvline(x=life[life['Year'] == 2000]['Life_expectancy'].median(), linestyle='--', color='tan')
plt.axvline(x=life[life['Year'] == 2015]['Life_expectancy'].median(), linestyle='--', color='darkcyan')
plt.text(life[life['Year'] == 2000]['Life_expectancy'].median() + 2, y=0.015, s='Median life expectancy at year 2000', color='tan')
plt.text(life[life['Year'] == 2015]['Life_expectancy'].median() + 2, y=0.02, s='Median life expectancy at year 2015', color='darkcyan')
plt.xlabel('Life expectancy')
plt.title('Average life expectancy of people around the world comparison between 2000 and 2015.')
plt.show()
sns.pointplot(data=life[life['Year'].isin([2000, 2015])], x='Region', y='Life_expectancy', hue='Year', estimator=np.median, palette=sns.color_palette('BrBG', 2))
plt.xlabel('Regions')
plt.ylabel('Life expectancy')
plt.xticks(rotation=90)
plt.title('Average life expectancy of population in each region comparison between 2000 and 2015')
plt.show()