{
 "metadata": {
  "name": "",
  "signature": "sha256:d580926b44e2de42389bfd8b08a03f0bfb6986c35fe468352dd140f775297e3c"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import bokeh\n",
      "bokeh.load_notebook()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import pandas as pd\n",
      "from collections import OrderedDict\n",
      "\n",
      "from bokeh.sampledata.olympics2014 import data\n",
      "from bokeh.charts import Donut\n",
      "\n",
      "# we throw the data into a pandas df\n",
      "df = pd.io.json.json_normalize(data['data'])\n",
      "# filter by countries with at least one medal and sort\n",
      "df = df[df['medals.total'] > 8]\n",
      "df = df.sort(\"medals.total\", ascending=False)\n",
      "\n",
      "# then, we get the countries and we group the data by medal type\n",
      "countries = df.abbr.values.tolist()\n",
      "gold = df['medals.gold'].astype(float).values\n",
      "silver = df['medals.silver'].astype(float).values\n",
      "bronze = df['medals.bronze'].astype(float).values\n",
      "\n",
      "# later, we build a dict containing the grouped data\n",
      "medals = OrderedDict(bronze=bronze, silver=silver, gold=gold)\n",
      "\n",
      "donut = Donut(medals, countries, notebook=True)\n",
      "donut.title(\"Medals Donut\").xlabel(\"countries\").ylabel(\"medals\")\n",
      "donut.width(800).height(800).show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import pandas as pd\n",
      "\n",
      "df = pd.DataFrame(medals)\n",
      "donut = Donut(medals, countries, title=\"Medals Donut\", xlabel=\"countries\", ylabel=\"medals\", notebook=True)\n",
      "donut.width(800).height(800).legend(True).show()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}