4.1. Data Structure¶
4.1.1. TableData¶
-
class
tabledata.
TableData
(table_name: Optional[str], headers: Sequence[str], rows: Sequence[T_co], dp_extractor: Optional[dataproperty._extractor.DataPropertyExtractor] = None, type_hints: Optional[Sequence[Union[str, Type[typepy.type._base.AbstractType], None]]] = None, max_workers: Optional[int] = None, max_precision: Optional[int] = None)[source]¶ Class to represent a table data structure.
Parameters: - table_name – Name of the table.
- headers – Table header names.
- rows – Data of the table.
-
as_dataframe
() → pandas.DataFrame[source]¶ Returns: Table data as a
pandas.DataFrame
instance.Return type: pandas.DataFrame
Sample Code: from tabledata import TableData TableData( "sample", ["a", "b"], [[1, 2], [3.3, 4.4]] ).as_dataframe()
Output: a b 0 1 2 1 3.3 4.4
Dependency Packages:
-
as_dict
(default_key: str = 'table') → Dict[str, List[OrderedDict[str, Any]]][source]¶ Parameters: default_key – Key of a returning dictionary when the table_name
is empty.Returns: Table data as a dict
instance.Return type: dict - Sample Code:
from tabledata import TableData TableData( "sample", ["a", "b"], [[1, 2], [3.3, 4.4]] ).as_dict()
- Output:
{'sample': [OrderedDict([('a', 1), ('b', 2)]), OrderedDict([('a', 3.3), ('b', 4.4)])]}
-
as_tuple
() → Iterator[Tuple][source]¶ Returns: Rows of the tuple.
Return type: list of
namedtuple
Sample Code: from tabledata import TableData records = TableData( "sample", ["a", "b"], [[1, 2], [3.3, 4.4]] ).as_tuple() for record in records: print(record)
Output: Row(a=1, b=2) Row(a=Decimal('3.3'), b=Decimal('4.4'))
-
column_dp_list
¶
-
dp_extractor
¶
-
filter_column
(patterns: Optional[str] = None, is_invert_match: bool = False, is_re_match: bool = False, pattern_match: tabledata._constant.PatternMatch = <PatternMatch.OR: 0>) → tabledata._core.TableData[source]¶
-
static
from_dataframe
(dataframe: pandas.DataFrame, table_name: str = '', type_hints: Optional[Sequence[Optional[Type[typepy.type._base.AbstractType]]]] = None, max_workers: Optional[int] = None) → TableData[source]¶ Initialize TableData instance from a pandas.DataFrame instance.
Parameters: - dataframe (pandas.DataFrame) –
- table_name (str) – Table name to create.
-
has_value_dp_matrix
¶
-
header_dp_list
¶
-
headers
¶ Table header names.
Type: Sequence[str]
-
is_empty
() → bool[source]¶ Returns: True
if the dataheaders
orvalue_matrix
is empty.Return type: bool
-
max_workers
¶
-
num_columns
¶
-
num_rows
¶ Number of rows in the tabular data.
None
if therows
is neither list nor tuple.Type: Optional[int]
-
rows
¶ Original rows of tabular data.
Type: Sequence
-
table_name
¶ Name of the table.
Type: str
-
value_dp_matrix
¶ DataProperty for table data.
Type: DataPropertyMatrix
-
value_matrix
¶ Converted rows of tabular data.
Type: DataPropertyMatrix