Analyzing US Economic Data and Building a Dashboard

Description

Extracting essential data from a dataset and displaying it is a necessary part of data science; therefore individuals can make correct decisions based on the data. In this assignment, I will extract some essential economic indicators from some data, I will then display these economic indicators in a Dashboard.

Gross domestic product (GDP) is a measure of the market value of all the final goods and services produced in a period. GDP is an indicator of how well the economy is doing. A drop in GDP indicates the economy is producing less; similarly an increase in GDP suggests the economy is performing better. In this lab, I will examine how changes in GDP impact the unemployment rate.

Defining a Function that Makes a Dashboard

In [ ]:
 I will import the following libraries.
In [9]:
import pandas as pd
from bokeh.plotting import figure, output_file, show,output_notebook
output_notebook()
Loading BokehJS ...

In this section, I define the function make_dashboard. The function will produce a dashboard as well as an html file.

In [10]:
def make_dashboard(x, gdp_change, unemployment, title, file_name):
    output_file(file_name)
    p = figure(title=title, x_axis_label='year', y_axis_label='%')
    p.line(x.squeeze(), gdp_change.squeeze(), color="firebrick", line_width=4, legend="% GDP change")
    p.line(x.squeeze(), unemployment.squeeze(), line_width=4, legend="% unemployed")
    show(p)

The dictionary links contain the CSV files with all the data. The value for the key GDP is the file that contains the GDP data. The value for the key unemployment contains the unemployment data.

In [ ]:
links={'GDP':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv',\
       'unemployment':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_unemployment.csv'}

Creating a dataframe that contains the GDP data and displaying the first five rows of the dataframe.

In [34]:
csv_path='https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_gdp.csv'
df1=pd.read_csv(csv_path)
In [35]:
df1.head()
Out[35]:
date level-current level-chained change-current change-chained
0 1948 274.8 2020.0 -0.7 -0.6
1 1949 272.8 2008.9 10.0 8.7
2 1950 300.2 2184.0 15.7 8.0
3 1951 347.3 2360.0 5.9 4.1
4 1952 367.7 2456.1 6.0 4.7

Creating a dataframe that contains the unemployment data and displaying the first five rows of the dataframe.

In [36]:
csv_path='https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_unemployment.csv'
df2=pd.read_csv(csv_path)
In [37]:
df2.head()
Out[37]:
date unemployment
0 1948 3.750000
1 1949 6.050000
2 1950 5.208333
3 1951 3.283333
4 1952 3.025000

Displaying a dataframe where unemployment was greater than 8.5%.

In [49]:
links={'unemployment':'https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/PY0101EN/projects/coursera_project/clean_unemployment.csv'}
csv_path=links['unemployment']
df2=pd.read_csv(csv_path)
df3=df2[df2['unemployment']>8.5]
df3
Out[49]:
date unemployment
34 1982 9.708333
35 1983 9.600000
61 2009 9.283333
62 2010 9.608333
63 2011 8.933333

Using the function make_dashboard to make a dashboard

In this section, I will call the function make_dashboard , to produce a dashboard. I will use the convention of giving each variable the same name as the function parameter.

In [52]:
csv_path1=links['GDP']
gdp_dataframe1=pd.read_csv(csv_path1)
x = pd.DataFrame(gdp_dataframe1, columns=['date'])
x.head()
Out[52]:
date
0 1948
1 1949
2 1950
3 1951
4 1952

Creating a new dataframe with the column 'change-current' called gdp_change from the dataframe that contains the GDP data.

In [74]:
csv_path2=links['GDP']
gdp_dataframe2=pd.read_csv(csv_path2)
gdp_change = pd.DataFrame(gdp_dataframe2, columns=['change-current'])
gdp_change.head()
Out[74]:
change-current
0 -0.7
1 10.0
2 15.7
3 5.9
4 6.0

Creating a new dataframe with the column 'unemployment' called unemployment from the dataframe that contains the unemployment data.

In [54]:
csv_path3=links['unemployment']
unemploy_dataframe1= pd.read_csv(csv_path3)
unemployment = pd.DataFrame(unemploy_dataframe1, columns=['unemployment'])
unemployment.head()
Out[54]:
unemployment
0 3.750000
1 6.050000
2 5.208333
3 3.283333
4 3.025000

Giving my dashboard a string title, and assigning it to the variable title

In [57]:
title = "GDP and Unemployment Data"

Finally, the function make_dashboard will output an .html in my direictory, just like a csv file. The name of the file is "index.html" and it will be stored in the varable file_name.

In [ ]:
file_name = "index.html"

Calling the function make_dashboard , to produce a dashboard. Assigning the parameter values accordingly.

In [73]:
make_dashboard(x = pd.DataFrame(gdp_dataframe1, columns=['date']), gdp_change = pd.DataFrame(gdp_dataframe2, columns=['change-current']), unemployment = pd.DataFrame(unemploy_dataframe1, columns=['unemployment']), title = "GDP and Unemployment Data", file_name = "index.html")
output_file("index.html")
output_notebook()
p = figure(title=title, x_axis_label='year', y_axis_label='%')
p.line(x.squeeze(), gdp_change.squeeze(), color="firebrick", line_width=4, legend="% GDP change")
p.line(x.squeeze(), unemployment.squeeze(), line_width=4, legend="% unemployed")
show(p)
    
Loading BokehJS ...
Loading BokehJS ...

References :