Bases: _Weakrefable
Options for parsing CSV files.
str
, optional (default â,â)
The character delimiting individual cells in the CSV data.
str
or False
, optional (default âââ)
The character used optionally for quoting CSV values (False if quoting is not allowed).
True
)
Whether two quotes in a quoted CSV value denote a single quote in the data.
str
or False
, optional (default False
)
The character used optionally for escaping special characters (False if escaping is not allowed).
False
)
Whether newline characters are allowed in CSV values. Setting this to True reduces the performance of multi-threaded CSV reading.
True
)
Whether empty lines are ignored in CSV input. If False, an empty line is interpreted as containing a single empty value (assuming a one-column CSV file).
callable()
, optional (default None
)
If not None, this object is called for each CSV row that fails parsing (because of a mismatching number of columns). It should accept a single InvalidRow argument and return either âskipâ or âerrorâ depending on the desired outcome.
Examples
Defining an example file from bytes object:
>>> import io >>> s = ( ... "animals;n_legs;entry\n" ... "Flamingo;2;2022-03-01\n" ... "# Comment here:\n" ... "Horse;4;2022-03-02\n" ... "Brittle stars;5;2022-03-03\n" ... "Centipede;100;2022-03-04" ... ) >>> print(s) animals;n_legs;entry Flamingo;2;2022-03-01 # Comment here: Horse;4;2022-03-02 Brittle stars;5;2022-03-03 Centipede;100;2022-03-04 >>> source = io.BytesIO(s.encode())
Read the data from a file skipping rows with comments and defining the delimiter:
>>> from pyarrow import csv >>> def skip_comment(row): ... if row.text.startswith("# "): ... return 'skip' ... else: ... return 'error' ... >>> parse_options = csv.ParseOptions(delimiter=";", invalid_row_handler=skip_comment) >>> csv.read_csv(source, parse_options=parse_options) pyarrow.Table animals: string n_legs: int64 entry: date32[day] ---- animals: [["Flamingo","Horse","Brittle stars","Centipede"]] n_legs: [[2,4,5,100]] entry: [[2022-03-01,2022-03-02,2022-03-03,2022-03-04]]
Methods
Attributes
The character delimiting individual cells in the CSV data.
Whether two quotes in a quoted CSV value denote a single quote in the data.
pyarrow.csv.ParseOptions
The character used optionally for escaping special characters (False if escaping is not allowed).
Whether empty lines are ignored in CSV input. If False, an empty line is interpreted as containing a single empty value (assuming a one-column CSV file).
Optional handler for invalid rows.
If not None, this object is called for each CSV row that fails parsing (because of a mismatching number of columns). It should accept a single InvalidRow argument and return either âskipâ or âerrorâ depending on the desired outcome.
Whether newline characters are allowed in CSV values. Setting this to True reduces the performance of multi-threaded CSV reading.
The character used optionally for quoting CSV values (False if quoting is not allowed).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4