CSV
Parsing and stringifying of Comma Separated Values (CSV) data.
The parsers map CSV data to an array of objects with field names mapping the header. For example, the CSV data:
maps to the following array of objects:
def
The def function automatically parses and stringifies CSV data to a Markdown table (it also works for XLSX).
def
also supports basic row filtering options that control how many rows you want to insert in the prompt.
CSV
Similarly to the JSON
class in JavaScript, the CSV
class provides methods to parse and stringify comma-separated values (CSV) data.
parse
The parse
method converts a CSV string into an array of objects. The first row is used as the header row.
If the CSV file does not have a header row, you can specify the column names as an array of strings. You can also specify a custom data separator.
You can use defData to serialize the rows
object to the prompt. defData
also supports basic row filtering options like def
.
stringify
The stringify
method converts an array of objects to a CSV string.
markdownify
The markdownify
method converts an array of objects into a markdown table. This encoding is more efficient with LLM tokenizers.
parsers
The parsers also provide a parser for CSV. Returns undefined
for invalid inputs. It supports files and parsing options.
Repair
You can specify the repair: true
option to fix common LLM mistakes around CSV.