{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Recognized Formats" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 1 (Array of Integers parameter)\n", "from beakerx import *\n", "\n", "TableDisplay({\"a\":100, \"b\":200, \"c\":300})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 1\n", "Image(\"../../resources/img/python/tableAPI/cell1_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 2 (2D Array of Integers parameter)\n", "TableDisplay([{\"a\":1}, {\"a\":10, \"b\":20}])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 2\n", "Image(\"../../resources/img/python/tableAPI/cell2_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 3 (Array of Decimals parameter)\n", "TableDisplay({\"a\":1/10, \"b\":1/20, \"c\":0.33})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 3\n", "Image(\"../../resources/img/python/tableAPI/cell3_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 4 (2D Array of Decimals parameter)\n", "TableDisplay([{\"a\":1/10}, {\"a\":1/100, \"b\":3.12345}])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 4\n", "Image(\"../../resources/img/python/tableAPI/cell4_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 5 (Array of Strings parameter)\n", "TableDisplay({\"a\":'string aaa', \"b\":'string bbb', \"c\":'string ccc'})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 5\n", "Image(\"../../resources/img/python/tableAPI/cell5_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 6 (2D Array of Strings parameter)\n", "TableDisplay([{\"a\":'a'}, {\"a\":'1a', \"b\":'2b'}])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 6\n", "Image(\"../../resources/img/python/tableAPI/cell6_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 7 (Array of Integer Arrays parameter)\n", "TableDisplay({\"a\":[1, 2, 3], \"b\":[10, 20, 30], \"c\":[100, 200, 300]})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 7\n", "Image(\"../../resources/img/python/tableAPI/cell7_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 8 (2D Array of Integer Arrays parameter)\n", "TableDisplay([\n", " {\"a\":[1, 2, 3]}, \n", " {\"a\":[10, 20, 30], \"b\":[100, 200, 300]}])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 8\n", "Image(\"../../resources/img/python/tableAPI/cell8_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 9 (2D Array of Integer,Decimal,String,Array Arrays parameter)\n", "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": [ "%%groovy\n", "// expected result of cell 9\n", "Image(\"../../resources/img/python/tableAPI/cell9_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 10 ([Integer,Decimal,String,Array] parameter)\n", "TableDisplay({\"a\":100, \"b\":1/20, \"c\":'c c c', \"d\":[100, 200, 300]})" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 10\n", "Image(\"../../resources/img/python/tableAPI/cell10_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 11 (2D Arrays of [Integer,Decimal,String,Array] parameter)\n", "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": [ "%%groovy\n", "// expected result of cell 11\n", "Image(\"../../resources/img/python/tableAPI/cell11_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 12 (numbers as name of Array keys (Array parameter))\n", "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": [ "%%groovy\n", "// expected result of cell 12\n", "Image(\"../../resources/img/python/tableAPI/cell12_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 13 (numbers as name of Array keys (2D Array parameter)\n", "row1 = {40:40, 1/40:1/40, 'c':'c'}\n", "row2 = {40:20, 1/40:1/20, 'c':'c c c', '[100, 200]':[100, 200, 300]}\n", "TableDisplay([row1, row2])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 13\n", "Image(\"../../resources/img/python/tableAPI/cell13_case1.png\")" ] }, { "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": [ "# 14\n", "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": [ "%%groovy\n", "// expected result of cell 14\n", "Image(\"../../resources/img/python/tableAPI/cell14_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from beakerx import *\n", "import pandas as pd\n", "import numpy as np\n", "pd.DataFrame(data=np.zeros((5,5)), index=pd.Int64Index([0, 1, 2, 3, 4], dtype='int64'))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 15\n", "pd.read_csv('../../resources/data/pd_index.csv', index_col=0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 15\n", "Image(\"../../resources/img/python/tableAPI/cell15_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 16\n", "pd.read_csv('../../../doc/resources/data/interest-rates.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 16\n", "Image(\"../../resources/img/python/tableAPI/cell16_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 17\n", "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": [ "%%groovy\n", "// expected result of cell 17\n", "Image(\"../../resources/img/python/tableAPI/cell17_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 18\n", "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": {}, "outputs": [], "source": [ "%%groovy\n", "// expected result of cell 18\n", "Image(\"../../resources/img/python/tableAPI/cell18_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "# 19\n", "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": [ "%%groovy\n", "// expected result of cell 19\n", "Image(\"../../resources/img/python/tableAPI/cell19_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 20\n", "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": [ "%%groovy\n", "// expected result of cell 20\n", "Image(\"../../resources/img/python/tableAPI/cell20_case1.png\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 21\n", "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": [ "%%groovy\n", "// expected result of cell 21\n", "Image(\"../../resources/img/python/tableAPI/cell21_case1.png\")" ] }, { "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 }