FuzzyTable¶
-
class
fuzzytable.
FuzzyTable
(path: Union[str, pathlib.Path], sheetname: Optional[str] = None, fields: Union[Iterable[str], Iterable[fuzzytable.patterns.fieldpattern.FieldPattern], str, fuzzytable.patterns.fieldpattern.FieldPattern, None] = None, header_row: Optional[int] = None, header_row_seek: Union[bool, int] = False, name: Optional[str] = None, approximate_match=False, min_ratio=sentinel.DefaultValue, missingfieldserror_active=False, mode=sentinel.DefaultValue, case_sensitive=sentinel.DefaultValue)¶ Extract a table from a spreadsheet.
This is the main class of fuzzytable. Instantiate it to extract the data. Then interact with the extracted table in one of four ways:
FuzzyTable
as a dictionary (keys are field names; values are column data)FuzzyTable.records
: sequence of records represented as dictionaries.- List of
FuzzyTable.field_names
objects. FuzzyTable.sheet
: additional worksheet attributes (e.g. header row number, path).
Methods
items
()Like dict.items()
.keys
()Like dict.keys()
.values
()Like dict.values()
.See learn_fuzzytable:
Parameters: - path (path-like
str
,pathlib.Path
object) – Must be a valid csv or excel file. - sheetname (
str
, defaultNone
) – Must be supplied ifpath
is an excel file. - header_row (
int
>=1, defaultNone
) –Row number m where FuzzyTable expects the headers to be.
None
: m = 1int
: m = header_row
- header_row_seek (
bool
,int
>= 1, defaultFalse
) –If Truthy: ignore header_row. Instead, FuzzyTable seeks the best fit header row within the first n rows.
int
: n = header_row_seek- other truthy value: n = 20
- fields (
str
or iterable thereof, defaultNone
) –None
: extract field_names for each non-None
cell in header row.str
or iterable thereof: extract matching field_names matching a cell in the header row.
- approximate_match (
bool
, default False) – If True, subfields will match if they are at least 60% similar to the field names supplied. This cutout value can be set with min_ratio. Deprecated in v0.18. To be removed in v1.0. Usemode
instead. - min_ratio (
float
, default None) – The minimum similarity threshold for matching headers. Must be float 0.0 < x <= 1.0 - name (
str
, default None) – Give this FuzzyTable instance a name. - mode (None or
str
) – Choose from'exact'
,'approx'
, or'contains'
.mode
overrides approximate_match and contains_match. - case_sensitive (None or
bool
, defaultTrue
) – Used when seeking header row and matching Fields to FieldPatterns.
-
records
¶ Return
Records
object, a generator yielding records (rows), each represented as a dictionary.
-
fields
¶ Return list of
SingleField
objects, with such attributes asname
,header
,data
,col_num
.
Raises: fuzzytable.exceptions.FuzzyTableError
– This is the module base exception. It is never itself raised, but you can use it to catch all exceptions raised by the FuzzyTable class. See Exceptions for all other exceptions raised by FuzzyTable.-
items
()¶ Like
dict.items()
. Return a generator yielding field name / column data tuples.
-
keys
()¶ Like
dict.keys()
. Return a generator yielding field names.
-
values
()¶ Like
dict.values()
. Return a generator yielding column data.