CSV (.csv)


    MIME type: text/comma-separated-values, text/csv
    CSV tabular data format.
    Stores records of numerical and textual information as lines, using commas to separate fields.
    Commonly used in spreadsheet applications as an exchange format.
    CSV is an acronym for Comma-Separated Values.
    Plain text format.
    Similar to TSV.

Import and Export

  • Import["file.csv"] returns a list of lists containing strings and numbers, representing the rows and columns stored in the file.
  • Import["file.csv",elem] imports the specified element from a CSV file.
  • Import["file.csv",{elem,sub1,}] imports subelements, specifically useful for partial data import.
  • The import format can be specified with Import["file","CSV"] or Import["file",{"CSV",elem,}].
  • Export["file.csv",expr] creates a CSV file from expr, using the InputForm of non-numeric elements at the second level.
  • Export["file.csv",expr] also works for structured input such as Dataset and TimeSeries.
  • See the reference pages for full general information on Import and Export.
  • ImportString and ExportString support the CSV format.

Notebook Interface

  • Save Selection As exports the selected part of a notebook as a CSV file.


  • General Import elements:
  • "Elements"list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings
    "Summary"summary of file size and dimensions
  • Data representation elements:
  • "Data"two-dimensional array
    "Grid"table data as a Grid object
    "RawData"two-dimensional array of strings
    "Dataset"table data as a Dataset
  • Import and Export use the "Data" element by default.
  • For partial data import, any data representation element elem can take row and column specifications in the form {elem, rows, cols}, where rows and cols can be any of the following:
  • nnth row or column
    n;;mfrom n through m
    {n1,n2,}specific rows or columns ni
  • Dimensions elements:
  • "RowCount"number of rows
    "MaxColumnCount"maximum number of columns


  • Import and Export options:
  • CharacterEncodingAutomaticraw character encoding used in the file
    "EmptyField"""how to represent empty fields
    "FillRows"Automaticwhether to fill all rows to the maximum column length
    "TextDelimiters""\""character used to delimit non-numeric fields
  • By default, Import attempts to interpret the data as "UTF8" encoded text. If any sequence of bytes stored in the file cannot be represented in "UTF8", Import uses "ISOLatin1" instead.
  • Export by default creates a "UTF8" encoded file.
  • Data fields containing commas and line separators are typically wrapped in double-quote characters. By default, Export uses double-quote characters as delimiters. Specify a different character using "TextDelimiters".
  • Double-quote characters delimiting text fields are not imported by default.
  • Import options:
  • "CurrencyTokens"{{"$", "£", "¥", "€"}, {"c", "¢", "p", "F"}}currency units to be skipped when importing numerical values
    "DateStringFormat"Nonedate format, given as a DateString specification
    "HeaderLines"0number of lines to assume as headers
    "IgnoreEmptyLines"Falsewhether to ignore empty lines
    "NumberPoint""."decimal point string
    "Numeric"Automaticwhether to import data fields as numbers if possible
    "SkipLines"0number of lines to skip at the beginning of the file
  • Possible settings for "HeaderLines" and "SkipLines" are:
  • nn rows to skip or to use as Dataset headers
    {rows,cols}rows and columns to skip or to use as headers
  • Import converts table entries formatted as specified by "DateStringFormat" to a DateObject.
  • Export options:
  • AlignmentNonehow data is aligned within table columns
    "TableHeadings"Noneheadings for table columns and rows
  • Possible settings for Alignment are None, Left, Center, and Right.
  • "TableHeadings" can be set to the following values:
  • Noneno labels
    Automaticgives successive integer labels for columns and rows
    {"col1","col2",}list of column labels
    {rhead,chead}specifies separate labels for the rows and columns
  • Export encodes line separator characters using the convention of the computer system on which the Wolfram Language is being run.


open allclose all

Basic Examples  (2)

Import a CSV file:

Click for copyable input

Read and plot all data from the file:

Click for copyable input

Export an array of expressions to CSV:

Click for copyable input
Click for copyable input

Scope  (5)

Import Elements  (14)

Import Options  (10)

Export Options  (7)

Applications  (1)

Possible Issues  (5)

See Also

"TSV"  "Table"  "XLS"  "Ini"

Introduced in 1999
| Updated in 2018