In [1]:
import pandas as pd
from datetime import datetime as dt, timedelta as td
import bokeh.plotting as bkp

from seabornify import seabornify

bkp.output_notebook()


BokehJS successfully loaded.

Ebola Virus Epidemic in West Africa

The Wikipedia page has proven to be a very helpful and up to date resource, and even contains a timeline with a running tally of casualties, aggregated from various official reports.

However, the few graphics on that page do not include breakdowns by country, so I decided to reflow the data through Bokeh.

These data are pulled from @cmyeaton's repository on GitHub (https://github.com/cmrivers/ebola) and are current as of September 10th, 2014. Rerunning this notebook should provide an updated view, assuming the data format does not change.


In [2]:
df = pd.read_csv('https://raw.githubusercontent.com/cmrivers/ebola/master/country_timeseries.csv',
                 index_col=0, parse_dates=True)
df.sort(inplace=True)
df.head()


Out[2]:
Day Cases_Guinea Cases_Liberia Cases_SierraLeone Cases_Nigeria Cases_Senegal Deaths_Guinea Deaths_Liberia Deaths_SierraLeone Deaths_Nigeria Deaths_Senegal
Date
2014-03-22 0 49 NaN NaN NaN NaN 29 NaN NaN NaN NaN
2014-03-24 2 86 NaN NaN NaN NaN 59 NaN NaN NaN NaN
2014-03-25 3 86 NaN NaN NaN NaN 60 NaN NaN NaN NaN
2014-03-26 4 86 NaN NaN NaN NaN 62 NaN NaN NaN NaN
2014-03-27 5 103 8 6 NaN NaN 66 6 5 NaN NaN

In [3]:
# set y_range of all plots to the same maximum value for accurate magnitude comparison
max_y = df.max().max() * 1.1

countries = ["Guinea", "Liberia", "SierraLeone", "Nigeria", "Senegal"]
plots = []

for country in countries:
    bkp.figure(title="Ebola Cases, Deaths in %s" %country,
               x_axis_type="datetime",
               y_range=(0, max_y),
               plot_width=600, plot_height=300,
               orientation="top_left", tools='')
    bkp.hold()
    cols = [x for x in df.columns if country in x]
    for col in cols:
        if "Deaths" in col:
            color="red"
            legend="Deaths"
        else:
            color="black"
            legend="Cases"
        bkp.line(list(df.index), df[col],
                 color=color, legend=legend,
                 linewidth=2, alpha=0.9)

    bkp.legend().orientation = "top_left"
    plot = bkp.curplot()
    seabornify(plot)
    plots.append(plot)

In [4]:
for plot in plots:
    bkp.show(plot)


Liberia

In the plots above, Liberia stood out quite a bit. The outbreak there has taken on an accelerated pace in the past couple of weeks.


In [6]:
# Liberia plot
country = "Liberia"
bkp.figure(title="Ebola Cases, Deaths in %s" %country,
           x_axis_type="datetime",
           y_range=(0, max_y),
           plot_width=600, plot_height=300,
           orientation="top_left", tools='')
bkp.hold()
cols = [x for x in df.columns if country in x]
for col in cols:
    if "Deaths" in col:
        color="red"
        legend="Deaths"
    else:
        color="black"
        legend="Cases"
    bkp.line(list(df.index), df[col],
             color=color, legend=legend,
             linewidth=2, alpha=0.9) 
    
latest = df.index.max()
two_weeks = latest - td(days=14)
two_months = latest - td(days=60)

bkp.quad([two_weeks], [latest], [max_y], [0], alpha=0.2, color="gray")
bkp.quad([two_months], [latest], [max_y], [0], alpha=0.2, color="gray")

bkp.legend().orientation = "top_left"

plot = bkp.curplot()
seabornify(plot)
bkp.show(plot)


WIP

df1 = df.truncate(before=two_weeks, after=latest) df2 = df.truncate(before=two_months, after=latest) now = df1.Cases_Liberia.ix[-1] then1 = df1.Cases_Liberia.ix[0] then2 = df2.Cases_Liberia.ix[0]