In [1]:
# import necessary libraries
import matplotlib.pyplot as plt
import pandas as pd

In [2]:
# define input parameters
input_file = "../data/World_historical_and_predicted_populations_in_percentage.csv"
output_file = "../results/plot.png"
region = 'Africa'
year_min = 1500
year_max = 2012

In [3]:
# read input data file
df = pd.read_csv(input_file)

In [4]:
# add index
df = df.set_index("Region", drop=False)

In [5]:
# select region and years based on input parameters
dfs = df.loc[region, str(year_min):str(year_max)]
dft = pd.DataFrame({'year': dfs.index.astype(int), 'percentage': dfs.values}, columns=['year', 'percentage'])

In [6]:
# create output plot and save it to a file
plot = plt.plot(dft['year'], dft['percentage'], color='blue')
plt.title('World population in {0}'.format(region))
plt.xlabel('year')
plt.ylabel('% of total world population')
plt.savefig(output_file)