Provide an introductory analysis into the growth rates within Senegal due to migration trends.
Senegal has a population of over 13.5 million,[36] about 42 percent of whom live in rural areas. Density in these areas varies from about 77 inhabitants per square kilometre (200/sq mi) in the west-central region to 2 per square kilometre (5.2/sq mi) in the arid eastern section.
The 2012 Revision of the World Population Prospects provides global demographic estimates and projections. This data is publicly available by the Population Division of the United Nations Department of Economic and Social Affairs of the United Nations Secretariat. The world population prospects are used widely throughout the United Nations and by many international organizations, research centers, academic researchers and the media.
Use the UN World Population Prospects Service to download a csv file. We are initially interested in a data file for Senegal with the following variables:
Once you've downloaded the data, upload it to your workbench.
Import the data into a dataframe so you can easily explore it.
In [2]:
import pandas as pd
df_pop_density = pd.read_csv('/resources/senegal_growth_migration.csv')
df_pop_density.head(5)
Out[2]:
We are not interested in the Variant
field and we know our data is limited to the country of Senegal
. So let us filter the data.
In [3]:
filtered_df = df_pop_density[['Variable','Year','Value']].dropna(how="any")
filtered_df
Out[3]:
That's more concise but let's create a pivot table from it so it's even easier to read.
In [4]:
df_pivot = filtered_df.pivot_table('Value', 'Year', 'Variable')
df_pivot.head(5)
Out[4]:
Now we can plot the data.
In [5]:
%matplotlib inline
In [62]:
import numpy as np
plt.figure(figsize = (6,4), dpi = 72)
plt.plot(df_pivot.ix[:,0:1], label="Net migration (per year), both sexes combined (thousands)")
plt.plot(df_pivot.ix[:,1:2], label="Net migration rate (per 1,000 population)")
plt.plot(df_pivot.ix[:,2:3], label="Population growth rate (%)")
plt.xlabel('Year')
plt.ylabel('Migration Rates')
plt.title('Annual Senegal Population Growth')
xvalues = list(df_pivot.index)
x = np.array(range(0,len(xvalues)))
plt.xticks(x,xvalues, rotation=70)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show()