tlc.core.objects.tables.from_table.reduced_table#

A procedural table where an input table has been reduced on one or more properties.

Module Contents#

Classes#

Class

Description

ReducedTable

A procedural table where an input table has been reduced on one or more properties.

API#

class tlc.core.objects.tables.from_table.reduced_table.ReducedTable(url: tlc.core.url.Url | None = None, created: str | None = None, row_cache_url: tlc.core.url.Url | None = None, row_cache_populated: bool | None = None, reduce_properties: list[str] | None = None, input_table_url: tlc.core.url.Url | tlc.core.objects.table.Table | None = None, init_parameters: Any = None)#

Bases: tlc.core.objects.table.Table

A procedural table where an input table has been reduced on one or more properties.

The reduction is performed by grouping all rows that have the same set of values, eg example_id, and then performing a reduction on each group. Currently the only reduction supported is average (mean) with some special handling for string and boolean value types.

Example:

from tlc.core import *

# create a table with two columns, example_id and value
table = TableFromPydict(data={"example_id": [1, 1, 2, 2], "value": [1, 2, 3, 4]})
# reduce the table by example_id, averaging the value column
reduced_table = ReducedTable(input_table_url=table, reduce_properties=["example_id"])
for row in reduced_table.table_rows:
    print(row)
# prints:
# {'example_id': 1, 'value': 1.5}
# {'example_id': 2, 'value': 3.5}