Plotting contents of an Excel File

This notebook simply demonstrates how to plot the contents of an excel file using pandas an the bokeh bokeh.charts high level interface


In [ ]:
import pandas as pd

filepath = "http://databank.worldbank.org/data/download/catalog/climate_change_download_0.xls"

In [ ]:
df = pd.ExcelFile(filepath).parse('Data')

In [ ]:
emissions = df[df['Series name'] == "CO2 emissions, total (KtCO2)"].copy()
for k in [2007, 2006, 2005]:
    emissions[k] = pd.to_numeric(emissions[k], errors='coerce')

emissions = emissions.sort_values(2007, ascending=False)
_remissions = emissions.iloc[:10, :]

In [ ]:
columns = ['Country code', 'Country name', 2007, 2006, 2005]
remissions = _remissions[columns]
remissions.columns = [str(x) for x in remissions.columns]

In [ ]:
from bokeh.plotting import figure, show, output_notebook, output_server, curdoc
from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Bar
from bokeh.charts.operations import blend

output_notebook()

In [ ]:
palette = ['#f7fcf5', '#e5f5e0','#c7e9c0', '#a1d99b','#74c476','#41ab5d','#238b45','#005a32', '#5A6351', '#000000']

p = Bar(remissions, label='years', group='Country name', palette=palette,
        values= blend('2007', '2006', '2005', name='values', labels_name='years'),
        title='Emissions', color='Country name', legend=True, responsive=True)
show(p)

In [ ]:
greys = ['#ffffff', '#f0f0f0', '#d9d9d9', '#bdbdbd', '#969696', '#737373', '#525252', '#252525', '#000000']
blues = ["#f7fbff" ,"#deebf7" ,"#c6dbef" ,"#9ecae1" ,"#6baed6" ,"#4292c6" ,"#2171b5" ,"#084594"]
p = Bar(remissions, label='Country name', group='year', palette = blues[1::3],
        values= blend('2007', '2006', '2005', name='values', labels_name='year'),
        title='Emissions', color='year', legend=True, responsive=True)
show(p)

In [ ]: