<jupyter_start><jupyter_text>Python API for Table DisplayIn 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.<jupyter_code>import pandas as pd
from beakerx import *
pd.read_csv('../resources/data/interest-rates.csv')
table = TableDisplay(pd.read_csv('../resources/data/interest-rates.csv'))
table.setAlignmentProviderForColumn('m3', TableDisplayAlignmentProvider.CENTER_ALIGNMENT)
table.setRendererForColumn("y10", TableDisplayCellRenderer.getDataBarsRenderer(False))
table.setRendererForType(ColumnType.Double, TableDisplayCellRenderer.getDataBarsRenderer(True))
table
df = pd.read_csv('../resources/data/interest-rates.csv')
df['time'] = df['time'].str.slice(0,19).astype('datetime64[ns]')
table = TableDisplay(df)
table.setStringFormatForTimes(TimeUnit.DAYS)
table.setStringFormatForType(ColumnType.Double, TableDisplayStringFormat.getDecimalFormat(4,6))
table.setStringFormatForColumn("m3", TableDisplayStringFormat.getDecimalFormat(0, 0))

table
table = TableDisplay(pd.read_csv('../resources/data/interest-rates.csv'))
table
#freeze a column
table.setColumnFrozen("y1", True)
#freeze a column to the right
table.setColumnFrozenRight("y10", True)
#hide a column
table.setColumnVisible("y30", False)

table.setColumnOrder(["m3", "y1", "y5", "time", "y2"])

table
table = TableDisplay(pd.read_csv('../resources/data/interest-rates.csv'))
table.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter("m3", TableDisplayCellHighlighter.FULL_ROW))

table<jupyter_output><empty_output><jupyter_text>Display mode: Pandas default<jupyter_code>beakerx.pandas_display_default()
pd.read_csv('../resources/data/interest-rates.csv')<jupyter_output><empty_output><jupyter_text>Display mode: TableDisplay Widget<jupyter_code>beakerx.pandas_display_table()
pd.read_csv('../resources/data/interest-rates.csv')<jupyter_output><empty_output><jupyter_text>Recognized Formats<jupyter_code>TableDisplay([{'y1':4, 'm3':2, 'z2':1}, {'m3':4, 'z2':2}])
TableDisplay({"x" : 1, "y" : 2})<jupyter_output><empty_output><jupyter_text>Programmable Table Actions<jupyter_code>mapList4 = [
   {"a":1, "b":2, "c":3},
   {"a":4, "b":5, "c":6},
   {"a":7, "b":8, "c":5}
]
display = TableDisplay(mapList4)

def dclick(row, column, tabledisplay):
    tabledisplay.values[row][column] = sum(map(int,tabledisplay.values[row]))

display.setDoubleClickAction(dclick)

def negate(row, column, tabledisplay):
    tabledisplay.values[row][column] = -1 * int(tabledisplay.values[row][column])

def incr(row, column, tabledisplay):
    tabledisplay.values[row][column] = int(tabledisplay.values[row][column]) + 1

display.addContextMenuItem("negate", negate)
display.addContextMenuItem("increment", incr)

display
mapList4 = [
   {"a":1, "b":2, "c":3},
   {"a":4, "b":5, "c":6},
   {"a":7, "b":8, "c":5}
]
display = TableDisplay(mapList4)

#set what happens on a double click
display.setDoubleClickAction("runDoubleClick")

display
print("runDoubleClick fired")
print(display.details)<jupyter_output><empty_output><jupyter_text>Set index to DataFrame<jupyter_code>df = pd.read_csv('../resources/data/interest-rates.csv')
df.set_index(['m3'])
df = pd.read_csv('../resources/data/interest-rates.csv')
df.index = df['time']
df<jupyter_output><empty_output><jupyter_text>Update cell<jupyter_code>dataToUpdate = [
   {'a':1, 'b':2, 'c':3},
   {'a':4, 'b':5, 'c':6},
   {'a':7, 'b':8, 'c':9}
]
tableToUpdate = TableDisplay(dataToUpdate)

tableToUpdate
tableToUpdate.values[0][0] = 99
tableToUpdate.sendModel()
tableToUpdate.updateCell(2,"c",121)
tableToUpdate.sendModel()<jupyter_output><empty_output><jupyter_text>HTML formatHTML format allows markup and styling of the cell's content.  Interactive JavaScript is not supported however.<jupyter_code>table = TableDisplay({'x': '<em style="color:red">italic red</em>',
                      'y': '<b style="color:blue">bold blue</b>',
                      'z': 'strings without markup work fine too'})
table.setStringFormatForColumn("Value", TableDisplayStringFormat.getHTMLFormat())
table<jupyter_output><empty_output><jupyter_text>Auto linking of URLsThe normal string format automatically detects URLs and links them.  An underline appears when the mouse hovers over such a string, and when you click it opens in a new window.<jupyter_code>TableDisplay({'Two Sigma': 'http://twosigma.com', 'BeakerX': 'http://BeakerX.com'})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1557231588287489, 'fraction_numerical': 0.017080745341614908, 'mean_word_length': 7.475563909774436, 'pattern_counts': {'":': 18, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '16897', 'license': 'Apache-2.0', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1559, 'n_words': 272, 'path': 'doc/python/TableAPI.ipynb', 'repo_name': 'murraju/beakerx', 'size': '4508'}