In [ ]:
import pandas as pd
from collections import OrderedDict
from bokeh._legacy_charts import Donut, output_notebook, show
from bokeh.sampledata.olympics2014 import data
In [ ]:
output_notebook()
In [ ]:
# throw the data into a pandas df
df = pd.io.json.json_normalize(data['data'])
# filter by countries with at least one medal and sort
df = df[df['medals.total'] > 8]
df = df.sort("medals.total", ascending=False)
# get the countries and we group the data by medal type
countries = df.abbr.values.tolist()
gold = df['medals.gold'].astype(float).values
silver = df['medals.silver'].astype(float).values
bronze = df['medals.bronze'].astype(float).values
# build a dict containing the grouped data
medals = OrderedDict(bronze=bronze, silver=silver, gold=gold)
In [ ]:
donut = Donut(
medals, countries, title='Medals Count, dict input',
xlabel='countries', ylabel='medals')
show(donut)
In [ ]:
df = pd.DataFrame(medals)
donut = Donut(
df, countries, title='Medals Count, pandas input',
xlabel='countries', ylabel='medals')
show(donut)
In [ ]:
from blaze import Data
medals = Data(df)
donut = Donut(medals, countries, title='Medals Count',
xlabel='countries', ylabel='medals', legend=False)
show(donut)
In [ ]: