Data Model¶
ft.fields¶
-
class
fuzzytable.datamodel.
SingleField
(header: str, col_num: int)¶ Represents a single column of your table.
A single FuzzyTable object will have several SingleField objects, stored as a list in
FuzzyTable.field_names
. SingleField objects are the source of truth for table contents. Remove a field fromFuzzyTable.field_names
and it disappears from theFuzzyTable
andFuzzyTable.records
views as well.>>> import fuzzytable >>> ft = fuzzytable.FuzzyTable('birthdays.csv') >>> first_name = ft.field_names[0] >>> first_name.col_num 1 >>> first_name.data ['John', 'Typhoid', 'Jane'] >>> str(first_name) "<SingleField 'first_name' 0x10dcce8>"
-
name
¶ return
str
, the unique identifier for this field. Matches the field name you passed to FuzzyTable. Otherwise, returnheader
.
-
data
¶ return list of cell values.
-
header
¶ return
str
, the value from the header cell. This may differ fromname
if fuzzy matching was specified.
-
col_num
¶ return
int
, column number, 1-indexed. For example, a field extracted from column B has a col_num of 2.
-
matched
¶ return
bool
. True if this field matches a field name passed to the FuzzyTable constructor.
-
-
class
fuzzytable.datamodel.
MultiField
(name, fields: List[fuzzytable.datamodel.fields.SingleField])¶ Represents one or more columns of your table.
ft.records¶
-
class
fuzzytable.datamodel.
Records
(fields: List[fuzzytable.datamodel.fields.SingleField], header_row_num: int, row_count: int, include_row_num: bool = True)¶ A sequence of dictionaries each representing a row of data.
>>> import fuzzytable >>> ft = fuzzytable.FuzzyTable('birthdays.csv') >>> ft.records[1] {'first_name': 'Typhoid', 'last_name': 'Mary', 'birthday': '2-Aug-83', 'row': 3}
Attributes
include_row_num
Default True
.Does not support deleting items. That must be done via
fuzzytable.datamodel.SingleField
-
include_row_num
¶ Default
True
. IfTrue
, all views will show an additional row SingleField.>>> list(ft.keys()) ['first_name', 'last_name', 'birthday', 'row'] >>> ft.records.include_row_num = False >>> list(ft.keys()) ['first_name', 'last_name', 'birthday'] >>> ft.records[1] {'first_name': 'Typhoid', 'last_name': 'Mary', 'birthday': '2-Aug-83'}
Note
This property needs to be moved to the FuzzyTable class.
-
ft.sheet¶
-
class
fuzzytable.datamodel.
Sheet
(header_row_num, row_count, ratio, path, sheetname)¶ Container for sheet metadata, e.g. path, header row number, number of rows, etc
>>> import fuzzytable >>> ft = fuzzytable.FuzzyTable('birthdays.csv') >>> ft.sheet.header_row_num 1 >>> ft.sheet.header_ratio 0.0 >>> ft.sheet.row_count 4 >>> ft.sheet.path WindowsPath('birthdays.csv') >>> ft.sheet.sheetname None
-
header_row_num
¶ int
row number, 1-indexed.
-
header_ratio
¶ float
percent match between desired field names and the found headers.0.0
if no field names were specified.
-
row_count
¶ int
total number of rows in the worksheet.
-
path
¶ pathlib.Path
object.str(path)
to convert to string.
-
sheetname
¶ str
name of worksheet if excel.
-