CSVFormat
class CSVFormat(
separator: str | int = ',',
quote_char: str | int = '"',
eol_char: str | int = '\n',
input_encoding: str = 'Utf8',
input_null_values: list | None = None,
input_missing_is_null: bool = True,
input_truncate_ragged_lines: bool = False,
input_comment_prefix: str | int | None = None,
input_try_parse_dates: bool = False,
input_decimal_comma: bool = False,
input_has_header: bool = True,
input_skip_rows: int = 0,
input_skip_rows_after_header: int = 0,
input_raise_if_empty: bool = True,
input_ignore_errors: bool = False,
output_include_header: bool = True,
output_datetime_format: str | None = None,
output_date_format: str | None = None,
output_time_format: str | None = None,
output_float_scientific: bool | None = None,
output_float_precision: int | None = None,
output_null_value: str | None = None,
output_quote_style: str | None = None,
output_maintain_order: bool = True,
)
Bases: FileFormat
Categories: file-format
The class of the CSV file format.
Attributes: separator (str | int): The separator of the CSV file. quote_char (str | int): The quote character of the CSV file. eol_char (str | int): The end of line character of the CSV file. input_encoding (str): The encoding of the CSV file. Only used when importing data. input_null_values (list | None): The null values of the CSV file. Only used when importing data. input_missing_is_null (bool): Whether missing values should be marked as null. Only used when importing data. input_truncate_ragged_lines (bool): Whether to truncate ragged lines of the CSV file. Only used when importing data. input_comment_prefix (str | int | None): The comment prefix of the CSV file. Only used when importing data. input_try_parse_dates (bool): Whether to try parse dates of the CSV file. Only used when importing data. input_decimal_comma (bool): Whether the CSV file uses decimal comma. Only used when importing data. input_has_header (bool): If the CSV file has header. Only used when importing data. input_skip_rows (int): How many rows should be skipped in the CSV file. Only used when importing data. input_skip_rows_after_header (int): How many rows should be skipped after the header in the CSV file. Only used when importing data. input_raise_if_empty (bool): If an error should be raised for an empty CSV. Only used when importing data. input_ignore_errors (bool): If the errors loading the CSV must be ignored. Only used when importing data. output_include_header (bool): Whether to include header in the CSV output. Only used when exporting data. output_datetime_format (str | None): A format string, with the specifiers defined by the chrono Rust crate. If no format specified, the default fractional-second precision is inferred from the maximum timeunit found in the frame’s Datetime cols (if any). Only used when exporting data. output_date_format (str | None): A format string, with the specifiers defined by the chrono Rust crate. Only used when exporting data. output_time_format (str | None): A format string, with the specifiers defined by the chrono Rust crate. Only used when exporting data. output_float_scientific (bool | None): Whether to use scientific form always (true), never (false), or automatically (None). Only used when exporting data. output_float_precision (int | None): Number of decimal places to write. Only used when exporting data. output_null_value (str | None): A string representing null values (defaulting to the empty string). Only used when exporting data. output_quote_style (str | None): Determines the quoting strategy used. Only used when exporting data.
- necessary (default): This puts quotes around fields only when necessary. They are necessary when fields contain a quote, separator or record terminator. Quotes are also necessary when writing an empty record (which is indistinguishable from a record with one empty field). This is the default.
- always: This puts quotes around every field. Always.
- never: This never puts quotes around fields, even if that results in invalid CSV data (e.g.: by not quoting strings containing the separator).
- non_numeric: This puts quotes around all fields that are non-numeric. Namely, when writing a field that does not parse as a valid float or integer, then quotes will be used even if they aren`t strictly necessary. output_maintain_order (bool): Maintain the order in which data is processed. Setting this to False will be slightly faster. Only used when exporting data.
Initializes the CSV format object.
Parameters
separatorstr | int, optionalThe separator of the CSV file.
quote_charstr | int, optionalThe quote character of the CSV file.
eol_charstr | int, optionalThe end of line character of the CSV file.
input_encodingstr, optionalThe encoding of the CSV file. Only used when importing data.
input_null_valueslist | None, optionalThe null values of the CSV file. Only used when importing data.
input_missing_is_nullbool, optionalWhether missing values should be marked as null. Only used when importing data.
input_truncate_ragged_linesbool, optionalWhether to truncate ragged lines of the CSV file. Only used when importing data.
input_comment_prefixstr | int | None, optionalThe comment prefix of the CSV file. Only used when importing data.
input_try_parse_datesbool, optionalWhether to try parse dates of the CSV file. Only used when importing data.
input_decimal_commabool, optionalWhether the CSV file uses decimal comma. Only used when importing data.
input_has_headerbool, optionalIf the CSV file has header. Only used when importing data.
input_skip_rowsint, optionalHow many rows should be skipped in the CSV file. Only used when importing data.
input_skip_rows_after_headerint, optionalHow many rows should be skipped after the header in the CSV file. Only used when importing data.
input_raise_if_emptybool, optionalIf an error should be raised for an empty CSV. Only used when importing data.
input_ignore_errorsbool, optionalIf the errors loading the CSV must be ignored. Only used when importing data.
output_include_headerbool, optionalWhether to include header in the CSV output. Only used when exporting data.
output_datetime_formatstr | None, optionalA format string, with the specifiers defined by the chrono Rust crate. If no format specified, the default fractional-second precision is inferred from the maximum timeunit found in the frame’s Datetime cols (if any). Only used when exporting data.
output_date_formatstr | None, optionalA format string, with the specifiers defined by the chrono Rust crate. Only used when exporting data.
output_time_formatstr | None, optionalA format string, with the specifiers defined by the chrono Rust crate. Only used when exporting data.
output_float_scientificbool | None, optionalWhether to use scientific form always (true), never (false), or automatically (None). Only used when exporting data.
output_float_precisionint | None, optionalNumber of decimal places to write. Only used when exporting data.
output_null_valuestr | None, optionalA string representing null values (defaulting to the empty string). Only used when exporting data.
output_quote_stylestr | None, optionalDetermines the quoting strategy used. Only used when exporting data. * necessary (default): This puts quotes around fields only when necessary. They are necessary when fields contain a quote, separator or record terminator. Quotes are also necessary when writing an empty record (which is indistinguishable from a record with one empty field). This is the default. * always: This puts quotes around every field. Always. * never: This never puts quotes around fields, even if that results in invalid CSV data (e.g.: by not quoting strings containing the separator). * non_numeric: This puts quotes around all fields that are non-numeric. Namely, when writing a field that does not parse as a valid float or integer, then quotes will be used even if they aren`t strictly necessary.
output_maintain_orderbool, optionalMaintain the order in which data is processed. Setting this to False will be slightly faster. Only used when exporting data.