Table

The Table class is used to create objects that can store and operate on two-dimensional data. This data is stored in a Pandas DataFrame, which can be accessed and changed directly using the .data attribute. It also contains some methods allowing users to add entire columns, either by user definition or by operating on an extant column.

class chromaquant.data.table.Table(data_frame: DataFrame | None = None, start_cell: str = '', sheet: str = '', header: str = '', results: Results = None)

Class used to store data alongside reporting information.

Parameters

data_framepandas DataFrame, optional

Data to be stored.

start_cellstr, optional

Reference to cell in Excel where data will be reported, referring to the top-left of report range. Must be a valid Excel cell (e.g., ‘A1’, ‘$B$2’).

sheetstr, optional

Name of Excel worksheet (sheet within workbook) where data will be reported.

header: str, optional

Header to add above a dataset, equivalent to a title.

results: Results, optional

Results object that mediates this DataSet.

Raises

ValueError

If sheet is set to a blank string.

ValueError

If start_cell is set to an invalid Excel cell.

add_category_column(column_name: str, categories: Categories, new_column_name: str = 'Category')

Method to add a categories column to the Table using passed Categories

Parameters

column_namestr

The name of the column to base categories on.

categoriesCategories

A Categories object used apply categories.

new_column_namestr, optional

The name of the column to store new categories in.

Returns

None

add_element_count_column(formula_column_name: str, element: str, new_column_name: str = '')

Method to add a molecular weight column to the Table

Parameters

formula_column_namestr

The name of the column containing chemical formulas.

new_column_namestr, optional

The name of the column to store molecular weights in.

Returns

None

add_formula(formula: Formula)
add_molecular_weight_column(formula_column_name: str, new_column_name: str = 'Molecular weight')

Method to add a molecular weight column to the Table

Parameters

formula_column_namestr

The name of the column containing chemical formulas.

new_column_namestr, optional

The name of the column to store molecular weights in.

Returns

None

add_table_column(column_name: str, column_values: Any = nan)

Method to add values to a column, either existing or new.

Parameters

column_namestr

The name of the existing or new column to reference.

column_valuesAny, optional

The value(s) to add to the column. Can be an iterable like a list or a single value.

Returns

None

add_table_column_from_function(column_name: str, function: Callable[[...], Any], *args: Any, **kwargs: Any)

Method to add a column to the Table using a passed function.

Parameters

column_namestr

The name of the new column.

functionCallable[…, Any]

A function that accepts the arbitrary positional and keyword arguments passed to add_table_column_from_function and returns a single value or iterable to add to a column.

Returns

None

property data: DataFrame | None

Get, set, or delete data stored in the DataSet. Common types include str, bool, int, float, list, dict, or pandas DataFrame.

import_csv_data(path: str, **kwargs: Any)

Reads .csv at passed path and sets self._data to result.

Parameters

pathstr

Full path to the data file of interest, including file name.

data_keystr

Name to assign imported data when using the “data” object.

Returns

None

insert(column: str, range: bool = False) str

Method that returns a unique identifier within a string insert. Used when composing dynamic formulas for reporting to Excel.

Returns

insert: str

Formula insert containing unique Table identifier.

match(import_DF: DataFrame, match_config: MatchConfig) DataFrame

Method to match a passed DataFrame to the current Table’s data.

Parameters

import_DFpd.DataFrame

DataFrame to match to current data.

match_configMatchConfig

MatchConfig object defining rules for matching process.

Returns

match_DFpd.DataFrame

Resulting DataFrame from matching.

property reference

Get the current reference object for the DataSet. Unable to set or delete this value as it is managed internally.

property sheet: str

Get, set, or delete the name of the Excel worksheet to report to.

property start_cell: str

Get, set, or delete the Excel reference where data will be reported.