image_output_2.png image_output_1.png
import pandas as pd

import scipy.stats as stats

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()

stat, pvalue = stats.wilcoxon(life[life['Year'] == 2015]['Life_expectancy'], life[life['Year'] == 2000]['Life_expectancy'])

alc_mortal = life[['Year', 'Region', 'Country', 'Adult_mortality', 'Alcohol_consumption']]

alc_mortal_EU = alc_mortal[alc_mortal['Region'] == 'European Union']
corr, pvalue = stats.spearmanr(alc_mortal_EU['Alcohol_consumption'], alc_mortal_EU['Adult_mortality'])
print('There is significant positive correlation between alcohol consumption and adult mortality rate in European population.')
print('Correlation coefficient : ', corr)
print('P-value : ', pvalue)
print('Caution for interpretion : It is important to note that correlation does not necessarily imply causation.')