 # Life Expectancy and GDP By Country and Year

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

import seaborn as sns

import statsmodels

import math

from numpy import median

print(data2.dtypes)

data2 = data2.rename(columns={“Life expectancy at birth (years)”: “Life_Expectancy”})

life_expectancy = data2[‘Life_Expectancy’]

print(np.mean(data2.GDP))

print(np.median(data2.GDP))

# Has life expectancy increased over time in the six nations? - Our observation is that Life expectancy has increased over time for all the six nations.

sns.barplot(data=data2 ,x=“Year”, y=“Life_Expectancy”, hue=“Country”)

plt.xticks(rotation=90)

plt.ylabel(“Life Expectancy”)

plt.title(‘Life Expectancy by Country’)

plt.show()

# VIOLINE PLOT LIFE EXPECTANCY COMPARISON - The observation here is that Zimbabwe has the lowest Life Expectancy out of all six countries.

fig = plt.subplots(figsize=(15, 10))

sns.violinplot (

``````data=data2,

x='Country' ,

y='Life_Expectancy',

palette="Blues")
``````

plt.ylabel(“Life Expectancy”)

plt.title(‘Life Expectancy Distrobution by Country’)

plt.show()

# LINE PLOT OF LIFE EXPECTANCY PER YEAR PER COUNTRY - Year by year, the Life Expactancy in Zimabwe has increased beyond 2014.

gr = sns.FacetGrid(

``````data2,

col="Country",

col_wrap=3,

height=4
``````

)

gr.fig.suptitle(“Line Plot for Life Expectancy period of year 2000 to 2015.”)

#gr.set_xticklabels(rotation=90)

plt.show()

# Has GDP increased over time in the six nations? - Our observation is that GDP has increased over time for China, USA, Mexico, Chile, and Germany overall. Zimbabwe GDP has been stagnating.

f, ax = plt.subplots(figsize=(10, 15))

ax = sns.barplot(data=data2, x=“Country”, y=“GDP”, hue=“Year”)

plt.xticks(rotation=90)

plt.ylabel(“GDP in Trillions of US Dollars”)

plt.title(‘GDP per Year’)

plt.show()

gr = sns.FacetGrid(

``````data2,

col="Country",

col_wrap=3,

height=4
``````

)

gr.fig.suptitle(“Line Plot for GDP period of year 2000 to 2015.”)

plt.show()

# GDP AND LIFE EXPECTANCY PER YEAR AND COUNTRY - We can clearly find corelation between very low GDP and Life Expectancy for Zimbabwe. However the same does not apply for Chie and Mexico as the GDP for these two countries is relatively low, but life expectancy is 80.5 and 76.7 retrospectively.

gr = sns.FacetGrid(

``````data2,

col='Year',

hue='Country',

col_wrap=4,

height=2
``````

)

gr.fig.suptitle(“Scatter Plot for GDP and Life Expectancy for the period of year 2000 to 2015.”)

plt.savefig(“codecademy_Scatter_Plots of GDP and Life Expectancy Data.png”)

plt.show()

CONCLUSION

Based on the data visuals, it is evident that there is overall link between the encrease of GDP and Life Expectancy by looking at Countries like Chine that has gone over rapid growth over the period between 2000 and 2015. Same can be confirmed for Zimbabwe where the GDP and Life Expectancy are the lowest out of all six countries in our dataset.

Congrats on finishing the project!

Just a suggestion, it’s a little difficult to read it as it’s posted. So, you could upload the notebook to your GitHub account as a repository w/a README file. You could then share it that way here. Plus, it can be part of your data portfolio if you should ever need one. 1 Like