CSV functions#
- baskerville.infer_csv(path, data_types=None, null_validator=None, has_headers=True, flexible=False, delimiter=',', escape=None, quote='"', quoting=True, trim=None, terminator='CRLF')#
Infers types from the file in the path given.
- Parameters:
path (str) -- Path to the csv file.
data_types (Optional[list[Union[baskerville.Text, baskerville.Literal, baskerville.Integer, baskerville.Float, baskerville.Unique, baskerville.Date, baskerville.Time, baskerville.DateTime, Callable[[str], bool]]]]) -- What data type validators to use to infer. See Validators.
null_validator (Optional[Union[baskerville.Text, baskerville.Literal, baskerville.Integer, baskerville.Float, baskerville.Unique, baskerville.Date, baskerville.Time, baskerville.DateTime, Callable[[str], bool]]]) -- A validator to use to identify nullable values. See Validators.
has_headers (bool) -- Whether the first line of the csv file is headers. If
True, then these are used as the column namesflexible (bool) -- Whether rows can have varying number of columns. If
False, then all rows must have the same number of columns or an error is thrown.delimiter (str) -- The csv delimiter. A single character string.
escape (Optional[str]) -- The escape character to use. By default, none is used.
quote (str) -- The csv quote character. A single character string.
quoting (bool) -- Whether to use quoting when reading the file.
trim (Optional[Literal["headers", "fields", "all"]]) -- Trim whitespace from headers, fields, or all records.
terminator (Union[Literal["CRLF"], str]) -- Specify the record terminator. The default is CRLF, which treats \r, \n or \r\n as a single record terminator.
- Returns:
The inferred
Fields.- Return type:
Example
mascots.csvName,LOC,Species Ferris,42,Crab Corro,7,Urchin
>>> import baskerville >>> fields = baskerville.infer_csv("mascots.csv") >>> print(baskerville.display_fields(fields)) ╭──────┬─────────┬─────────╮ │ Name │ LOC │ Species │ ├──────┼─────────┼─────────┤ │ Text │ Integer │ Text │ │ │ Float │ │ │ │ Text │ │ ╰──────┴─────────┴─────────╯