Skip to content

Table#

Table widget

Available in backends: qt

Signals#

  • changed(object) - Emitted when the widget value changes.
  • label_changed(str) - Emitted when the widget label changes.
  • native_parent_changed(object) - Emitted with the backend widget when the widget parent changes.

Table #

Bases: ValueWidget, _ReadOnlyMixin, MutableMapping[TblKey, list]

A widget to represent columnar or 2D data with headers.

Tables behave like plain dicts, where the keys are column headers and the (list-like) values are column data.

Parameters:

  • value ((dict, dataframe, list, array, tuple), default: None ) –

    Table data (and/or header data), in one of the accepted formats:

    • list or list-of-lists : [column_values] or [[row_vals], ..., [row_vals]]
    • dict-of-dicts : {column_header -> {row_header -> value}}
    • dict-of-lists : {column_header -> [column_values]}
    • list-of-row-records : [{column_headers -> value}, ... , {column_headers -> value}]
    • split-dict-of-lists :
    • tuple-of-values : ([values], [row_headers], [column_headers])
    • dict-of-pandas-series : {column_header -> Series(values)}
  • index (Collection, default: None ) –

    A sized iterable container of row headers. By default, row headers will be tuple(range(len(data))). Values provided here override any implied in value.

  • columns (Collection, default: None ) –

    A sized iterable container of column headers. By default, column headers will be tuple(range(len(data[0]))). Values provided here override any implied in value.

  • **kwargs (Unpack[WidgetKwargs], default: {} ) –

    Additional kwargs will be passed to the magicgui.widgets.Widget constructor.

Attributes:

  • value (dict) –

    Returns a dict with the keys data, index, and columns ... representing the 2D (list of lists) tabular data, row headers, and column headers, respectively. If set, will clear and update the table using the new data.

  • data (DataView) –

    A DataView instance that provides numpy-like indexing (with get/set/delete) onto the 2D data array, For example table.data[0,2] gets the data in the cell of the first row, 3rd column. Works with numpy slice syntax.

  • column_headers (tuple) –

    The current column headers. Can be set with a new sequence to change

  • row_headers (tuple) –

    The current row headers. Can be set with a new sequence to change

  • shape (tuple of int) –

    The shape of the table in (rows, columns).

  • size (int) –

    The number of cells in the table.

Methods:

  • keys

    Return a TableHeadersView, providing a view on this table's headers. Use axis='row' for row headers.

  • items

    Return a TableItemsView, providing a view on this table's items, as 2-tuples of (header, data). Use axis='row' for (row_header, row_data)

  • clear

    Clear all table data and headers.

  • to_dataframe

    Returns a pandas dataframe representation of this table. (requires pandas)

  • to_dict

    Return one of many different dict-like representations of table and header data. See docstring of :meth:to_dict for details.

Events

changed Emitted whenever a cell in the table changes. The value will have a dict of information regarding the cell that changed: {'data': x, 'row': int, 'column': int, 'column_header': str, 'row_header': str} CURRENTLY: only emitted on changes in the GUI. not programmatic changes.

column_headers: tuple property writable #

Return column headers.

data: DataView property writable #

Return DataView object for this table.

row_headers: tuple property writable #

Return row headers.

shape: tuple[int, int] property #

Return shape of table widget (rows, cols).

size: int property #

Return shape of table widget (rows, cols).

value: dict[TblKey, Collection] property writable #

Return dict with current data, index, and columns of the widget.

__delitem__(key: TblKey) -> None #

Delete a column from the table.

__getitem__(key: TblKey) -> list #

Get a column from the table.

__hash__() -> int #

Make table hashable.

__iter__() -> Iterator #

Yield column headers.

__len__() -> int #

Return number of columns.

__new__(value: TableData | None = None, *, index: Collection | None = None, columns: Collection | None = None, **kwargs: Any) -> Table #

Just for the signature.

__repr__() -> str #

Return string repr.

__setitem__(key: TblKey, v: Collection) -> None #

Set a column in the table. If k doesn't exist, make a new column.

clear() -> None #

Clear the table.

delete_row(*, index: int | Sequence[int] | None = None, header: Any | Sequence[Any] | None = None) -> None #

Delete row(s) by index or header.

Parameters:

  • index (int or Sequence[int], default: None ) –

    Index or indices of row(s) to delete.

  • header (Any or Sequence[Any], default: None ) –

    Header or headers of row(s) to delete.

items(axis: str = 'column') -> TableItemsView[TblKey, list] #

Return a set-like object providing a view on this table's items.

keys(axis: str = 'column') -> HeadersView[TblKey] #

Return a set-like object providing a view on this table's headers.

to_dataframe() -> pandas.DataFrame #

Convert TableData to dataframe.

to_dict(orient: str = 'dict') -> list | dict #

Convert the Table to a dictionary.

The type of the key-value pairs can be customized with the parameters (see below).

Parameters:

  • orient (str {'dict', 'list', 'series', 'split', 'records', 'index'}, default: 'dict' ) –

    Determines the type of the values of the dictionary.

    • 'dict' (default) : dict like {column -> {index -> value}}
    • 'list' : dict like {column -> [values]}
    • 'split' : dict like
    • 'records' : list like [{column -> value}, ... , {column -> value}]
    • 'index' : dict like {index -> {column -> value}}
    • 'series' : dict like {column -> Series(values)}