readTsvStr
Read TSV String to DataFrame
Reads any TSV String to a DataFrame.
Note that if input dataframe contains duplicate column names, they will be automatically renamed in the resulting DataFrame.
Parameters you can use to customize the reading process include, for instance, delimiter, header, colTypes, readLines, and parserOptions. See the param list below for all settings.
The integration is built upon Deephaven CSV.
Similar Functions
With the overloads of DataFrame.readTsv(), you can read any TSV by File, Path, URL, or InputStream. Reading by file path or URL can also be done by passing a String.
For example, DataFrame.readTsv("input.tsv") or with some options:
file = File("input.tsv"),
parserOptions = ParserOptions(locale = Locale.US),
colTypes = mapOf("a" toColType.Int, ColType.DEFAULTtoColType.String),
readLines = 1000L,
)
ZIP (.zip) or GZIP (.gz) files are supported by default. compression is automatically detected.
You can also read "raw" TSV data from a String like this:
DataFrame.readTsvStr("a,b,c", delimiter = ",")
Parameters
The raw data to read in the form of a String.
The field delimiter character. Default: '\t'.
Ignored if hasFixedWidthColumns is true.
The character set the input is encoded in. Default: null
If null, the Charset will be read from the BOM of the provided input, defaulting to UTF-8 if no BOM is found.
Whether the data has fixed-width columns instead of a single delimiter. Default: false.
Fixed-width columns can occur, for instance, in multi-space delimited data, where the columns are separated by multiple spaces instead of a single delimiter, so columns are visually aligned. Column widths are determined by the header in the data (if present), or manually by setting fixedColumnWidths.
The fixed column widths. Default: empty list.
Requires hasFixedWidthColumns. If empty, the column widths will be determined by the header in the data (if present), else, this manually sets the column widths. The number of widths should match the number of columns.
The expected ColType per column name. Default: empty map, a.k.a. infer every column type.
If supplied for a certain column name (inferred from data or given by header), the parser will parse the column with the specified name as the specified type, else it will infer the type.
e.g. colTypes = mapOf("colName" toColType.Int). You can also set ColType.DEFAULTtoColType.X to set a default column type, like ColType.String.
The number of lines to skip before reading the header and data. Default: 0.
Useful for files with metadata, or comments at the beginning, or to give a custom header.
The maximum number of lines to read from the data. Default: null.
If null, all lines will be read.
Optional parsing options for columns initially read as String. Default: null.
Can configure locale, date format, double parsing, skipping types, etc.
If parserOptions or any of the arguments are null, the global parser configuration (org.jetbrains.kotlinx.dataframe.DataFrame.Companion.parser) will be queried.
The only exceptions are:
nullStrings, which, ifnull, will take the global setting +["", "NA", "N/A", "null", "NULL", "None", "none", "NIL", "nil"].skipTypes, which will always addtypesDeephavenAlreadyParsesto the given types or the global setting.
Whether to skip intermediate empty lines. Default: false.
If false, empty lines will be interpreted as having empty values if allowMissingColumns.
Whether to allow rows with fewer columns than the header. Default: true.
If true, rows that are too short will be interpreted as empty values.
Whether to ignore rows with more columns than the header. Default: true.
If true, rows that are too long will have those columns dropped.
The quote character. Default: ".
Used when field- or line delimiters should be interpreted as literal text.
For example: 123,"hello, there",456, would correspond to: 123; hello, there; 456.
Whether to ignore leading and trailing blanks around non-quoted fields. Default: true.
Whether to ignore leading and trailing blanks inside quoted fields. Default: false.
Whether to parse the data in parallel. Default: true.
If true, the data will be read and parsed in parallel by the Deephaven parser. This is usually faster but can be turned off for debugging.