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.
I will import the following libraries.
import pandas as pd
from bokeh.plotting import figure, output_file, show,output_notebook
output_notebook()
In this section, I define the function make_dashboard
.
The function will produce a dashboard as well as an html file.
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.
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'}
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)
df1.head()
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)
df2.head()
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
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.
csv_path1=links['GDP']
gdp_dataframe1=pd.read_csv(csv_path1)
x = pd.DataFrame(gdp_dataframe1, columns=['date'])
x.head()
Creating a new dataframe with the column 'change-current'
called gdp_change
from the dataframe that contains the GDP data.
csv_path2=links['GDP']
gdp_dataframe2=pd.read_csv(csv_path2)
gdp_change = pd.DataFrame(gdp_dataframe2, columns=['change-current'])
gdp_change.head()
Creating a new dataframe with the column 'unemployment'
called unemployment
from the dataframe that contains the unemployment data.
csv_path3=links['unemployment']
unemploy_dataframe1= pd.read_csv(csv_path3)
unemployment = pd.DataFrame(unemploy_dataframe1, columns=['unemployment'])
unemployment.head()
Giving my dashboard a string title, and assigning it to the variable title
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
.
file_name = "index.html"
Calling the function make_dashboard
, to produce a dashboard. Assigning the parameter values accordingly.
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)