Data visualization dashboard demo

Sean Chang, July 2016
In [8]:
# this is a data viz dashboard example using ipython notebook
# ipython notebook can be executed from shell and saved to html like this file.
# usage example: execute this file daily to generate a prediction performance report.
# input: csv data
# output: html report w interactive plots + without any additional library 
In [ ]:
# to execute from shell, save and run the following python script:
def build_arg_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--currency', help="get currency",
        type=str, required=True)
    return parser

if __name__ == '__main__':
    NS = build_arg_parser().parse_args()

    # if date is an input
    os.environ['date'] = str(NS.date)
    
    report_path = 'data_visualization_dashboard'

    if call(["ipython", "nbconvert", "--to=html",
             "--execute", report_path, '.ipynb',
             "--ExecutePreprocessor.timeout=270"]):
        raise Exception('failed to run ipython notebook')
In [3]:
import numpy as np
import pandas as pd

from datetime import datetime
from bokeh.io import output_notebook
from bokeh.plotting import figure, show
from bokeh.charts import TimeSeries
from IPython.display import display
from subprocess import call
TOOLS = "pan, box_zoom, reset, save, box_select"
output_notebook()
Loading BokehJS ...
In [4]:
def plotter(currency):
    dat = pd.read_csv('data/{currency}USD.csv'.format(currency = currency))
    dat['time'] = pd.to_datetime(dat.time).apply(lambda x: x.date()).apply(pd.to_datetime)
    p = TimeSeries(dat, x = 'time', y = 'rate', title = currency, 
                   ylabel='exchange rate', xlabel='date')
    show(p)
In [7]:
currencies = ['JPY', 'AUD', 'EUR', 'GBP', 'NZD', 'CHF']
for currency in currencies: 
    plotter(currency)