Skip to main content

CSVLoader

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

LoaderCharacteristic
File FormatCSV
Data FormatTables
File TypeText
File Extension.csv, .tsv, .dsv
MIME Typestext/csv, text/tab-separated-values, text/dsv
Supported APIsload, parse, parseSync, parseInBatches

Usage​

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

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

A complication with the CSV format is that CSV files can come with or without an initial header line. While the CSVLoader will attempt to detect if the first line is a header, this can fail. If you know the format of the file you can use options.csv.header to specify how to handle the first line.

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

const data = await load(url_to_csv_with_header, CSVLoader, {csv: {header: true});
const data = await load(url_to_csv_without_header, CSVLoader, {csv: {header: false});

Options​

OptionTypeDefaultDescription
csv.shape'object-row-table' | 'array-row-table'object-row-tableOutput rows as objects keyed by column name or as arrays of values.
csv.optimizeMemoryUsagebooleanfalseOptimize memory usage at the cost of additional parsing time.
csv.headerboolean | 'auto'autoIf true, treat the first row as field names. If false, treat the first row as data. 'auto' attempts to detect headers.
csv.columnPrefixstringcolumnPrefix used when generating column names for files without headers (for example, column1, column2, ...).
csv.quoteCharstring"Character used to quote fields.
csv.escapeCharstring"Character used to escape the quote character within a field.
csv.dynamicTypingbooleantrueConvert numeric and boolean values from strings to their native types.
csv.commentsbooleanfalseSkip lines that start with a comment indicator.
csv.skipEmptyLinesboolean | 'greedy'trueSkip empty lines; 'greedy' also skips lines that only contain whitespace.
csv.delimitersToGuessstring[][',', '\t', '|', ';']Delimiters to try when no delimiter is specified.