Life Expectancy vs Gross Domestic Product using Data Analytics!
By: Dhruvil Shah
Tags: Python, Data Science, Data Analysis, Programming, Data Visualization

Terms in use:

GDP: Gross Domestic Product (GDP) is the overall monetary or consumer value of all finished goods and services produced within the boundaries of a nation over a given period. It acts as a large measure of overall domestic output, as a detailed scorecard of the economic health of the country. GDP is measured in US dollars. Life Expectancy at Birth Year (LEABY): The word “Life Expectancy” refers to how many years a person may expect to live. By definition, life expectancy is based on an estimation of the average age at which members of a given demographic group will be at death.

The data used in this project is gathered from the World Bank. This project aims to try and identify the relationship between the GDP and Life Expectancy of six countries namely, Australia, China, Germany, India, the United States of America, and Zimbabwe with the help of Data visualization.

Find the code of this project here and connect with me on LinkedIn. Let’s get to the coding part.

1. Visualizing LEABY per country for the last 20 years (1999–2018)

Violin plots help us to visualize and compare more than one distributions at a time. There are two symmetrical ‘KDE — Kernel Density Estimator — plots’ along the middle line. The ‘black thick line’ at the center shows the interquartile range while the lines that extend from it to the ends represent a 95% confidence interval. The white dot in the middle shows the median of the distribution. Learn more about violin plots here.

Below is the code for creating the violin plots of each of the six countries.

from matplotlib import pyplot as plt

import pandas as pd

import seaborn as sns

df = pd.read_csv("final.csv") fig = plt.subplots(figsize=(12, 7))

sns.violinplot(data=df, x='Country', y='LEABY', fontsize='large', fontweight='bold')

plt.savefig("violin.png",bbox_inches='tight')

Output:

Violin plot: Life Expectancy at Birth Year (LEABY) vs Country

We can see that variance is the highest in the data of Zimbabwe country and the lowest in the United States. Also, the median Life Expectancy is the largest in Australia and the lowest in Zimbabwe.

2. Visualizing the correlation between GDP and LEABY

A FacetGrid takes in a function and creates individual graphs for which you specify the arguments.

Next, to see the correlation between GDP and LEABY, let’s see the facet grid of scatter graphs, mapping GDP as a function of Life Expectancy by country. Below are the matplotlib scatter plots for the plot (LEABY vs GDP).

g = sns.FacetGrid(df, col='Year', hue='Country', col_wrap=4, size=2)

g = (g.map(plt.scatter, 'GDP', 'LEABY', edgecolor="w").add_legend())

Life Expectancy vs Gross Domestic Product

Scatter plots are easy to interpret. We can notice the changes over the last 20 years in the countries from the plot above. China and the United States are the countries that have moved most along the x-axis i.e. GDP has increased over the years while Zimbabwe has moved most along the y-axis i.e. life expectancy there has increased over time. Further, Life expectancy in Australia and the United States seems to be constant for the last 20 years.

Furthermore, a great way to visualize a variable over time is by using a line plot. Now, instead of the scatter plots if we use line plots for GDP and Life expectancy individually we could more easily see the changes over time. Below is the FacetGrid of line graphs mapping GDP by country.

g3 = sns.FacetGrid(df, col="Country", col_wrap=3, size=4)

g3 = (g3.map(plt.plot, "Year", "GDP").add_legend())

FacetGrid of line graphs mapping GDP by country

United States of America has the highest GDP among these countries and it steadily seems to be increasing over the years. As we can see that the GDP in China has drastically increased in the past 10 years, it is interesting to know what happened in China that made this sudden change? There are many reasons behind that, which you can find in the below article.

Now let’s look at a similar plot as above for LEABY. Below is the FacetGrid of line graphs mapping Life expectancy by country.

g3 = sns.FacetGrid(df, col="Country", col_wrap=3, size=4)

g3 = (g3.map(plt.plot, "Year", "LEABY").add_legend())

FacetGrid of line graphs mapping Life Expectancy by Country

It is from 2010–2015 when there is a huge change in the Life expectancy of these six countries. The United States has had the least change in life expectancy over time, could this be the outcome of having high GDP? But then there is the case of Australia where the GDP is lower compared to other ones’, but the life expectancy is still almost equal to that of the United States. It seems that the relation between GDP and Life expectancy is not that simple.