{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import pylab as plt" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import param\n", "import datetime as dt\n", "import panel as pn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Panel short demo" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "def interact_example(a=2, b=3):\n", " \n", " plot = plt.figure()\n", " ax = plot.add_subplot(111)\n", " \n", " pd.Series({'a':a, 'b':b}).plot(kind='bar',ax=ax)\n", "\n", "\n", " plt.tight_layout()\n", " plt.close(plot)\n", " return plot" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING:param.Column00005: Displaying Panel objects in the notebook requires the panel extension to be loaded. Ensure you run pn.extension() before displaying objects in the notebook.\n" ] }, { "data": { "text/plain": [ "Column\n", " [0] Column\n", " [0] IntSlider(end=6, name='a', start=-2, value=2)\n", " [1] IntSlider(end=9, name='b', start=-3, value=3)\n", " [1] Row\n", " [0] Matplotlib(Figure, name='interactive00004')" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pn.interact(interact_example)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Dashboard" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "import sqlite3" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "con = sqlite3.connect('../Chapter16/data/311.db')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "Q = '''\n", "SELECT date(created_date) as date, lower(borough) as boro, complaint_type, COUNT(*) as complaints\n", "FROM raw WHERE borough != 'Unspecified' GROUP BY 1,2,3;\n", "'''" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "DATA = pd.read_sql_query(Q, con)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | date | \n", "boro | \n", "complaint_type | \n", "complaints | \n", "
|---|---|---|---|---|
| 0 | \n", "2019-01-01 | \n", "bronx | \n", "APPLIANCE | \n", "5 | \n", "
| 1 | \n", "2019-01-01 | \n", "bronx | \n", "Air Quality | \n", "1 | \n", "
| 2 | \n", "2019-01-01 | \n", "bronx | \n", "Blocked Driveway | \n", "98 | \n", "
| \"),e=0;e<7;e++)n.push(' | '+y(t,e,!0)+\" | \");return\"
|---|