{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Recognized Formats" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from beakerx import *\n", "\n", "TableDisplay({\"a\":100, \"b\":200, \"c\":300})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TableDisplay([{\"a\":1}, {\"a\":10, \"b\":20}])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TableDisplay({\"a\":1/10, \"b\":1/20, \"c\":0.33})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TableDisplay([{\"a\":1/10}, {\"a\":1/100, \"b\":3.12345}])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TableDisplay({\"a\":'a a a', \"b\":'b b b', \"c\":'c c c'})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TableDisplay([{\"a\":'a'}, {\"a\":'1a', \"b\":'2b'}])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TableDisplay({\"a\":[1, 2, 3], \"b\":[10, 20, 30], \"c\":[100, 200, 300]})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TableDisplay([\n", " {\"a\":[1, 2, 3]}, \n", " {\"a\":[10, 20, 30], \"b\":[100, 200, 300]}])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "row1 = {\"a\":100, \"b\":200, \"c\":300}\n", "row2 = {\"a\":1/10, \"b\":1/20, \"c\":0.33}\n", "row3 = {\"a\":'a a a', \"b\":'b b b', \"c\":'c c c'}\n", "row4 = {\"a\":[1, 2, 3], \"b\":[10, 20, 30], \"c\":[100, 200, 300]}\n", "TableDisplay([row1, row2, row3, row4])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TableDisplay({\"a\":100, \"b\":1/20, \"c\":'c c c', \"d\":[100, 200, 300]})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "row1 = {\"a\":10, \"b\":1/10, \"c\":'c', \"d\":[100, 200]}\n", "row2 = {\"a\":100, \"b\":1/20, \"c\":'c c c', \"d\":[100, 200, 300]}\n", "TableDisplay([row1, row2])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "TableDisplay({10:20, 1/10:1/20, 'c':'c c c', '[100, 200]':[100, 200, 300]})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "row1 = {10:10, 1/10:1/10, 'c':'c'}\n", "row2 = {10:20, 1/10:1/20, 'c':'c c c', '[100, 200]':[100, 200, 300]}\n", "TableDisplay([row1, row2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Python API for Table Display\n", "\n", "In addition to APIs for creating and formatting BeakerX's interactive table widget, the Python runtime configures pandas to display tables with the interactive widget instead of static HTML." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from beakerx import *\n", "\n", "df = pd.DataFrame({\"runway\": [\"24\", \"36L\"]})\n", "\n", "TableDisplay(df)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pd.read_csv('../../../doc/resources/data/interest-rates.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table2 = TableDisplay(pd.read_csv('../../../doc/resources/data/interest-rates-small.csv'))\n", "table2.setAlignmentProviderForColumn('m3', TableDisplayAlignmentProvider.CENTER_ALIGNMENT)\n", "table2.setRendererForColumn(\"y10\", TableDisplayCellRenderer.getDataBarsRenderer(False))\n", "table2.setRendererForType(ColumnType.Double, TableDisplayCellRenderer.getDataBarsRenderer(True))\n", "table2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df3 = pd.read_csv('../../../doc/resources/data/interest-rates-small.csv')\n", "df3['time'] = df3['time'].str.slice(0,19).astype('datetime64[ns]')\n", "table3 = TableDisplay(df3)\n", "table3.setStringFormatForTimes(TimeUnit.DAYS)\n", "table3.setStringFormatForType(ColumnType.Double, TableDisplayStringFormat.getDecimalFormat(2,3))\n", "table3.setStringFormatForColumn(\"m3\", TableDisplayStringFormat.getDecimalFormat(0, 0))\n", "table3" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "table4 = TableDisplay(pd.read_csv('../../../doc/resources/data/interest-rates-small.csv'))\n", "#freeze a column\n", "table4.setColumnFrozen(\"y1\", True)\n", "#freeze a column to the right\n", "table4.setColumnFrozenRight(\"y10\", True)\n", "#hide a column\n", "table4.setColumnVisible(\"y30\", False)\n", "table4" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table5 = TableDisplay(pd.read_csv('../../../doc/resources/data/interest-rates-small.csv'))\n", "#Columns in the list will be shown in the provided order. Columns not in the list will be hidden.\n", "table5.setColumnOrder([\"m3\", \"y1\", \"y10\", \"time\", \"y2\"])\n", "table5" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "colNames = [\"m3\",\"y30\",\"time\",\"y5\",\"y7\",\"spread\"]\n", "row1 = [7.8981, 8.2586, \"1990-01-30 19:00:00.000 -0500\", 8.1195, 8.1962, 0.3086]\n", "row2 = [2.0021, 8.5037, \"1990-02-27 19:00:00.000 -0500\", 8.4247, 8.4758, 0.4711]\n", "row3 = [2.0021, 3.5037, \"1990-05-27 19:00:00.000 -0500\", 1.4247, 4.4758, 5.4711]\n", "table6 = TableDisplay(pd.DataFrame([row1, row2, row3], columns=colNames))\n", "table6.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"m3\", TableDisplayCellHighlighter.FULL_ROW))\n", "table6" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }