Let’s have a look at trends in GDP per Capita between 1970 - 2022!
GDP per Capita
Gross domestic product (GDP) is a monetary measure of the total market value of all the final goods and services produced and rendered in a specific time period by a countryor countries.
GDP per capita is the total value of a country’s finished goods and services (Gross domestic product) divided by its total population (per capita).
The data used in this analysis is sourced with thanks from this data set on kaggle. The data consists of a csv file with column of Country names and a column for each year from 1970 to 2022. The GDP per capita values (in US Dollars) are expressed for the respective countries and years.
Data Wrangling
Data wrangling is the process of transforming data from one form into another form that is well suited to the purpose at hand. In our case that means transforming the data into a form that will be easy to create visualisations from. Thankfully the original data set is well tempered so there will be little for us to do before jumping into the visualisations.
Tools used
I’m using the following tools to work with the data, create visualisations and generate reports:
# import librariesimport pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport seaborn as sns import matplotlib.ticker as tickerimport matplotlib.ticker as mtickfrom matplotlib.ticker import ScalarFormatter# set up for the visuals%matplotlib inline plt.rcParams['figure.figsize'] = [8.0, 4.0]plt.rcParams['figure.dpi'] =80plt.rc('legend',fontsize=9)plt.rcParams['axes.edgecolor'] ='grey'# import datad = pd.read_csv('data/Per Capita GDP of All Countries 1970 to 2022.csv')d = d.drop(columns='Sr.No').set_index('Country').T# make a table of the percentiles for each yearqs = [0.1,0.2,0.25,0.3,0.4,0.5,0.6,0.7,0.75,0.8,0.9]gdp_percentiles = pd.DataFrame(index = [f"{x*100:.0f}th Percentile"for x in qs ], data = [d.quantile(x, axis=1) for x in qs]).T
Data Visualisations
There are many ways we can visualise the data. Different perspectives may offer different insights.
Overall trend over time
Let’s take a look at the overall trend in GDP per Capita over time …
Code
# construct the plotfig, ax = plt.subplots()gdp_percentiles.loc[:,['50th Percentile']].plot(color='black',alpha=0.4, ls='-', lw=5.0, ax=ax)# format axisax.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, _: '${:,g}'.format(y)))ax.spines[['right', 'top']].set_visible(False)# format legend, title, etcax.get_legend().set_title("")ax.get_legend().get_frame().set_linewidth(0.0)ax.set_title('GDP Per Capita (1970-2022)', loc='left')plt.tight_layout()
Figure 1: GDP per Capita (1970 - 2022)
Average (median) GPD per capita has increased from below $500 in 1970 to almost $7000 by 2022. A lot of that increase looks like it took place in the 2000s
Median
We have used the median for our average. The median is the value at or below which 50% of the data points exist. The median is also know as the 50th percentile.
By plotting other percentiles we can get a more detailed picture of the distribution of our data. Let’s add in the 25th percentile and the 75th percentile. We can roughly think of the 25th percentile as being the point below which the GDP per capita of the poorest 25% of countries exists; and the 75th percentile as being the point above which the GDP per capita of the richest 25% of countries exists.
As our data spans a broad range of values, a log scale may help us see some of the patterns more clearly. Below we use a log scale for the y-axis.
Code
# construct the plotfig, ax = plt.subplots()gdp_percentiles.loc[:,['25th Percentile']].plot(color='black',alpha=0.4, ls='--', lw=2.5,logy=True, ax=ax)gdp_percentiles.loc[:,['50th Percentile']].plot(color='black',alpha=0.4, ls='-', lw=5.0, ax=ax)gdp_percentiles.loc[:,['75th Percentile']].plot(color='black',alpha=0.4, ls='--', lw=2.5, ax=ax)# format axisax.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, _: '${:,g}'.format(y)))ax.spines[['right', 'top']].set_visible(False)# format legend, title, etcax.get_legend().set_title("")ax.get_legend().get_frame().set_linewidth(0.0)ax.set_title('GDP Per Capita (1970-2022)',loc ='left')plt.tight_layout()
Figure 2: GDP per Capita (1970 - 2022) with log y-axis
Comparing two countries
For illustrative purposes we will highlight two countries, so that their respective trends in GDP per capita can be compared over time.
The two charts below show the same data from slightly different perspectives. GDP per capita chart uses the absolute GDP per capita values where as the GDP per capita relative to world median chart expresses the GDP per capita values as a proportion of the world median, with the median indexed to 100 (resulting in a perspective that has more of a focus on the performance of countries relative to each other, rather than the absolute changes).