Skip to content

Tables API

tabloom.table

Create and edit pandas-backed tables, load external data, and render styled visuals.

The public Table class supports incremental edits, data exports, and matplotlib output. Import it from tabloom or tabloom.table. Constructor options, method parameters, return values, and exceptions are documented below.

Table Source

Table(data: Any = None, *, columns: Sequence[Hashable] | None = None, title: str | None = None, theme: str = 'plain', style: Mapping[str, Any] | None = None, figsize: tuple[float, float] | None = None, copy: bool = True)

An editable pandas table with plain black-and-white graphical defaults.

Parameters:

Name Type Description Default
data Any

Column mapping, records, rows, DataFrame, or None.

None
columns Sequence[Hashable] | None

Column names; required for positional rows.

None
title str | None

Optional title above the rendered table.

None
theme str

Plain black and white by default. Choose blue, soft_blue, or dark_blue for colored headers and alternating row backgrounds.

'plain'
style Mapping[str, Any] | None

Overrides: header_background, header_color, row_colors, font_size, cell_alignment, and relative column_widths.

None
figsize tuple[float, float] | None

Optional figure width and height in inches.

None
copy bool

Copy an incoming DataFrame by default. With False, share it until an editing method replaces the underlying frame.

True

from_dataframe Source classmethod

from_dataframe(df: DataFrame, **kwargs: Any) -> Table

Construct a table from a pandas DataFrame.

Parameters:

Name Type Description Default
df DataFrame

Source DataFrame.

required
**kwargs Any

Table constructor options. Data is copied by default; copy=False shares the exact DataFrame until an editing method replaces it.

{}

Returns:

Type Description
Table

A new table with the requested visual settings.

Raises:

Type Description
TypeError

The input is not a single DataFrame.

from_csv Source classmethod

from_csv(path: str | Path, *, title: str | None = None, theme: str = 'plain', style: Mapping[str, Any] | None = None, **kwargs: Any) -> Table

Read a CSV file using pandas.

Parameters:

Name Type Description Default
path str | Path

Path to the input CSV file.

required
title str | None

Optional title for graphical output.

None
theme str

Name of the visual theme.

'plain'
style Mapping[str, Any] | None

Table-specific visual overrides.

None
**kwargs Any

Options forwarded to pandas.read_csv, such as sep or index_col.

{}

Returns:

Type Description
Table

A new table containing the loaded data.

from_excel Source classmethod

from_excel(path: str | Path, *, title: str | None = None, theme: str = 'plain', style: Mapping[str, Any] | None = None, **kwargs: Any) -> Table

Read one Excel sheet using pandas and openpyxl.

Parameters:

Name Type Description Default
path str | Path

Path to an Excel workbook, normally an .xlsx file.

required
title str | None

Optional title for graphical output.

None
theme str

Name of the visual theme.

'plain'
style Mapping[str, Any] | None

Table-specific visual overrides.

None
**kwargs Any

Options forwarded to pandas.read_excel, including a single sheet_name. The default engine is openpyxl.

{}

Returns:

Type Description
Table

A new table containing one sheet.

Raises:

Type Description
TypeError

The options request multiple sheets instead of one DataFrame.

from_json Source classmethod

from_json(path: str | Path, *, title: str | None = None, theme: str = 'plain', style: Mapping[str, Any] | None = None, **kwargs: Any) -> Table

Read a JSON file using pandas.

Parameters:

Name Type Description Default
path str | Path

Path to the JSON data file.

required
title str | None

Optional title for graphical output.

None
theme str

Name of the visual theme.

'plain'
style Mapping[str, Any] | None

Table-specific visual overrides.

None
**kwargs Any

Options forwarded to pandas.read_json, such as orient or lines.

{}

Returns:

Type Description
Table

A new table containing the loaded data.

add_row Source

add_row(row: Any) -> Table

Append one mapping or positional row.

Parameters:

Name Type Description Default
row Any

A mapping from column names to values, or values in column order. Missing mapping keys receive missing values. Unknown keys are rejected.

required

Returns:

Type Description
Table

This table, allowing method chaining.

Raises:

Type Description
TypeError

The row is not a mapping or sequence.

ValueError

Columns are missing, unknown, or have the wrong value count.

add_rows Source

add_rows(rows: Iterable[Any]) -> Table

Append multiple rows without partially applying invalid input.

Parameters:

Name Type Description Default
rows Iterable[Any]

An iterable of row mappings or positional sequences. An entirely empty table infers columns from mappings; positional rows require existing columns. An empty iterable leaves the table unchanged.

required

Returns:

Type Description
Table

This table, allowing method chaining.

Raises:

Type Description
TypeError

A row is not a mapping or sequence.

ValueError

A row has unknown columns or an incorrect value count.

add_column Source

add_column(name: Hashable, values: Iterable[Any]) -> Table

Append a column whose values follow the current row order.

Parameters:

Name Type Description Default
name Hashable

A new, unique column name.

required
values Iterable[Any]

One value per existing row. Series index labels are not aligned.

required

Returns:

Type Description
Table

This table, allowing method chaining.

Raises:

Type Description
ValueError

The column already exists or its length differs from the table.

update_row Source

update_row(position: int, row: Any) -> Table

Update cells identified by a zero-based row position.

Parameters:

Name Type Description Default
position int

Nonnegative row position, independent of pandas index labels.

required
row Any

A partial mapping of cells to update, or a complete sequence in column order. Unspecified mapping keys retain their previous values.

required

Returns:

Type Description
Table

This table. Failed assignments do not partially change the stored frame.

Raises:

Type Description
TypeError

The position or row has an unsupported type.

IndexError

The position is negative or outside the current table.

ValueError

Row keys or sequence length do not match the schema.

remove_row Source

remove_row(position: int) -> Table

Remove one row while preserving the remaining index labels.

Parameters:

Name Type Description Default
position int

Nonnegative, zero-based row position rather than an index label.

required

Returns:

Type Description
Table

This table, allowing method chaining.

Raises:

Type Description
TypeError

The position is not an integer.

IndexError

The position is negative or outside the current table.

rename_column Source

rename_column(old: Hashable, new: Hashable) -> Table

Rename a column without overwriting an existing column.

Parameters:

Name Type Description Default
old Hashable

Existing column name.

required
new Hashable

Replacement name. Reusing the same name is allowed.

required

Returns:

Type Description
Table

This table, allowing method chaining.

Raises:

Type Description
KeyError

The old column does not exist.

ValueError

The replacement collides with another column.

to_dataframe Source

to_dataframe(*, copy: bool = True) -> pd.DataFrame

Return table data without graphical styling.

Parameters:

Name Type Description Default
copy bool

Return an independent DataFrame copy by default. If False, return the same object as table.df.

True

Returns:

Type Description
DataFrame

The copied or shared pandas DataFrame.

to_csv Source

to_csv(path: str | Path, **kwargs: Any) -> None

Export table data as CSV without graphical styling.

Parameters:

Name Type Description Default
path str | Path

Destination data filename.

required
**kwargs Any

Options forwarded to pandas DataFrame.to_csv. The index is omitted unless index=True is supplied.

{}

to_excel Source

to_excel(path: str | Path, **kwargs: Any) -> None

Export table data as EXCEL without graphical styling.

Parameters:

Name Type Description Default
path str | Path

Destination data filename.

required
**kwargs Any

Options forwarded to pandas DataFrame.to_excel. The index is omitted and openpyxl is the default engine.

{}

to_json Source

to_json(path: str | Path, **kwargs: Any) -> None

Export table data as JSON without graphical styling.

Parameters:

Name Type Description Default
path str | Path

Destination data filename.

required
**kwargs Any

Options forwarded to pandas DataFrame.to_json. The default orientation is records; pass orient to override it.

{}

render Source

render(*, head: int | None = None, tail: int | None = None) -> tuple[Figure, Axes]

Create a fresh matplotlib rendering of the current data.

Parameters:

Name Type Description Default
head int | None

Render only the first n rows. None leaves rows unrestricted.

None
tail int | None

Render only the last n rows. Cannot be combined with head.

None

Returns:

Type Description
Figure

A Figure/Axes pair owned by the caller. Call plt.close(fig) when it is

Axes

no longer needed. Direct changes to table.df are reflected immediately.

Raises:

Type Description
TypeError

A preview count is not an integer.

ValueError

Preview counts, column names, dimensions, or widths are invalid.

show Source

show(*, head: int | None = None, tail: int | None = None) -> None

Display a preview of the table without changing its data.

Parameters:

Name Type Description Default
head int | None

Show the first n rows. When neither option is supplied, show 10.

None
tail int | None

Show the last n rows instead. Cannot be combined with head.

None

Raises:

Type Description
TypeError

A preview count is not an integer.

ValueError

A preview count is negative or both options are supplied.

In a notebook, the Figure is displayed inline without writing an image file and its pyplot registration is cleaned up automatically. Outside notebooks, display uses the active graphical backend.

save Source

save(path: str | Path, *, dpi: float = 200, **kwargs: Any) -> None

Save the styled table as PNG, PDF, or SVG.

Parameters:

Name Type Description Default
path str | Path

Destination filename, including .png, .pdf, or .svg extension.

required
dpi float

Positive raster resolution in dots per inch; defaults to 200.

200
**kwargs Any

Additional matplotlib Figure.savefig options, such as transparent or bbox_inches.

{}

Raises:

Type Description
ValueError

The extension or DPI is unsupported.

The temporary rendering is closed after export. Use to_csv, to_excel, or to_json to export data rather than graphical styling.