View in nbviewer

Assignment 4

Before working on this assignment please read these instructions fully. In the submission area, you will notice that you can click the link to Preview the Grading for each step of the assignment. This is the criteria that will be used for peer grading. Please familiarize yourself with the criteria before beginning the assignment.

This assignment requires that you to find at least two datasets on the web which are related, and that you visualize these datasets to answer a question with the broad topic of economic activity or measures (see below) for the region of Abu Dhabi, Abu Dhabi, United Arab Emirates, or United Arab Emirates more broadly.

You can merge these datasets with data from different regions if you like! For instance, you might want to compare Abu Dhabi, Abu Dhabi, United Arab Emirates to Ann Arbor, USA. In that case at least one source file must be about Abu Dhabi, Abu Dhabi, United Arab Emirates.

You are welcome to choose datasets at your discretion, but keep in mind they will be shared with your peers, so choose appropriate datasets. Sensitive, confidential, illicit, and proprietary materials are not good choices for datasets for this assignment. You are welcome to upload datasets of your own as well, and link to them using a third party repository such as github, bitbucket, pastebin, etc. Please be aware of the Coursera terms of service with respect to intellectual property.

Also, you are welcome to preserve data in its original language, but for the purposes of grading you should provide english translations. You are welcome to provide multiple visuals in different languages if you would like!

As this assignment is for the whole course, you must incorporate principles discussed in the first week, such as having as high data-ink ratio (Tufte) and aligning with Cairo’s principles of truth, beauty, function, and insight.

Here are the assignment instructions:

  • State the region and the domain category that your data sets are about (e.g., Abu Dhabi, Abu Dhabi, United Arab Emirates and economic activity or measures).
  • You must state a question about the domain category and region that you identified as being interesting.
  • You must provide at least two links to available datasets. These could be links to files such as CSV or Excel files, or links to websites which might have data in tabular form, such as Wikipedia pages.
  • You must upload an image which addresses the research question you stated. In addition to addressing the question, this visual should follow Cairo's principles of truthfulness, functionality, beauty, and insightfulness.
  • You must contribute a short (1-2 paragraph) written justification of how your visualization addresses your stated research question.

What do we mean by economic activity or measures? For this category you might look at the inputs or outputs to the given economy, or major changes in the economy compared to other regions.


  • Wikipedia is an excellent source of data, and I strongly encourage you to explore it for new data sources.
  • Many governments run open data initiatives at the city, region, and country levels, and these are wonderful resources for localized data sources.
  • Several international agencies, such as the United Nations, the World Bank, the Global Open Data Index are other great places to look for data.
  • This assignment requires you to convert and clean datafiles. Check out the discussion forums for tips on how to do this from various sources, and share your successes with your fellow students!


Looking for an example? Here's what our course assistant put together for the Ann Arbor, MI, USA area using sports and athletics as the topic. Example Solution File

In [4]:
"""Coursera: python for datascience, matplotlib - Assignment 4 solution"""
%matplotlib notebook
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, YearLocator

def gdp_inflation_data(file_name, sheet):
    """Read gdp and inflation data"""
    data = pd.read_excel('assignment_data/{}.xlsx'.format(file_name), sheetname=sheet)
    data.set_index('year', inplace=True)
    if 'inflation_rate' in list(data):
        data.inflation_rate = data.inflation_rate*100
    data = data.iloc[::-1] # place dates in ascending order
    data.index = pd.to_datetime(data.index, format='%Y')
    return data

def plot_data():
    """Plot the figure"""

    ng_gdp = gdp_inflation_data('data_gdp', 'NG')
    ng_inflation = gdp_inflation_data('data_inflation', 'NG')
    uae_gdp = gdp_inflation_data('data_gdp', 'UAE')
    uae_inflation = gdp_inflation_data('data_inflation', 'UAE')

    fig = plt.figure(facecolor='lightblue', figsize=(12, 8))
    ax_gdp = plt.subplot(2, 1, 1)
    ax_inf = plt.subplot(2, 1, 2, sharex=ax_gdp)
    years = YearLocator()
    yrfmt = DateFormatter("%Y")

    ax_inf.plot_date(ng_inflation.index, ng_inflation.inflation_rate, 'g-o', label='Nigeria')
    ax_inf.plot_date(uae_inflation.index, uae_inflation.inflation_rate, 'r-o', label='UAE')
    ax_gdp.plot_date(ng_gdp.index, ng_gdp.GDP_bn_dol, 'g-o', label='Nigeria')
    ax_gdp.plot_date(uae_gdp.index, uae_gdp.GDP_bn_dol, 'r-o', label='UAE')

    ax_gdp.set(ylabel="GDP (billions of $)")
    ax_gdp.legend(loc="upper left")

    ax_inf.set(ylabel="Inflation rate (in %)")
    ax_inf.legend(loc="lower left")
    title = "Variation of GDP and inflation rate of Nigeria and UAE between 2005 and 2016"
    fig.suptitle(title, fontsize=16)


    plt.savefig("output/comparing_gdp_inflation.png", facecolor=fig.get_facecolor(), dpi=100)
    plt.savefig("output/comparing_gdp_inflation.pdf", facecolor=fig.get_facecolor(), dpi=100)

C:\Users\Chidimmo\.virtualenvs\ds-UkbacWyt\lib\site-packages\pandas\io\ FutureWarning: The `sheetname` keyword is deprecated, use `sheet_name` instead
In [ ]: