Chevron DownAPI Reference

CSVLoader

Streaming loader for comma-separated value and delimiter-separated value encoded files.

LoaderCharacteristic
File Extension.csv, .dsv
File TypeText
File FormatRFC4180
Data FormatClassic Table
Supported APIsload, parse, parseSync, parseInBatches

Usage

import {CSVLoader} from '@loaders.gl/csv';
import {load} from '@loaders.gl/core';

const data = await load(url, CSVLoader);
// or
const data = await load(url, CSVLoader, {csv: options});

Options

OptionTypeDefaultDescription
csv.headerBoolean | StringautoIf true, the first row of parsed data will be interpreted as field names. If false, the first row is interpreted as data.
csv.rowFormatStringautoCan be set to 'object' go force rows to be objects, or 'auto'.
csv.columnPrefixStringcolumnThe prefix to use when naming columns for CSV files with no header. Defaults to 'column1', 'column2' etc.
csv.delimiterStringauto-detectThe delimiting character.
csv.newlineStringauto-detectThe newline sequence. Must be \r, \n, or \r\n.
csv.quoteCharString"The character used to quote fields.
csv.escapeCharString"The character used to escape the quote character within a field.
csv.dynamicTypingBooleantrueIf true, numeric and boolean data values will be converted to their type (instead if strings. Note: if you disable dynamicTyping, you need to explicitly set header to a boolean value. Otherwise, header: 'auto' would automatically treat the first row as a header.
csv.commentsStringfalseComment indicator (for example, "#" or "//"). Lines starting with this string are skipped.
csv.skipEmptyLinesStringfalseIf true, lines that are completely empty (those which evaluate to an empty string) will be skipped. If set to 'greedy', lines that don't have any content (those which have only whitespace after parsing) will also be skipped.
csv.transformFunction-A function to apply on each value. The function receives the value as its first argument and the column number or header name when enabled as its second argument. The return value of the function will replace the value it received. The transform function is applied before dynamicTyping.
csv.delimitersToGuessArray`[',', '\t', '', ';']`
csv.fastModeBooleanauto-detectForce set "fast mode". Fast mode speeds up parsing significantly for large inputs but only works when the input has no quoted fields. Fast mode will be auto enabled if no " characters appear in the input.

Remarks:

  • A complication with the CSV format is that CSV files can come with or without an initial header line. Use options.csv.header to specify how to handle the first line.
  • Many options are passed on to papaparse, so the papaparse docs can serve as a source for more information.