Wolfram Computation Meets Knowledge

Wolfram Language & System Documentation Center Wolfram Language Home Page »

CSV (.csv)

Background & Context

Import & Export

Import Elements

Options

Examples

open allclose all

Basic Examples  (3)

Import a CSV file:

Read and plot all data from the file:

Import a CSV file as a Dataset with headers:

Export an array of expressions to CSV:

Scope  (4)

Export a Dataset:

Use Values to remove headers from a dataset:

Use the "HeaderLines" option to import table headers:

Export a TimeSeries:

Export an EventSeries:

Export a QuantityArray:

Import Elements  (17)

"Data"  (6)

Import a CSV file as a 2D list of values:

This is also the default element:

Import a single row from a CSV file:

Import some specific rows from a CSV file:

Import the first 10 rows of a CSV file:

Import a single row and column from a CSV file:

Import a single column from a CSV file:

"Dataset"  (3)

Import a CSV file as a Dataset:

Use "HeaderLines" to use the first row as column headers:

Use "SkipLines" to only import the data of interest:

"Dimensions"  (1)

Get the dimensions from a CSV file:

If all rows in the file do not have the same number of columns, the maximum number of columns is used:

"Grid"  (1)

Import CSV data as a Grid:

"MaxColumnCount"  (1)

Get the maximum number of columns from a CSV file:

"RawData"  (3)

Import CSV data as raw strings:

Compare to "Data":

By default for "RawData", "Numeric"->False is used:

Use "Numeric"->True:

By default for "RawData", "FillRows"->True is used:

Use "FillRows"->False:

"RowCount"  (1)

Get the maximum number of columns from a CSV file:

"Summary"  (1)

Summary of a CSV file:

Import Options  (10)

CharacterEncoding  (1)

The character encoding can be set to any value from $CharacterEncodings:

"CurrencyTokens"  (1)

Currency tokens are automatically skipped:

Use "CurrencyTokens"->None to include all currency tokens:

"DateStringFormat"  (1)

Convert dates to a DateObject using the date format specified:

By default, no conversion is happening:

"EmptyField"  (1)

Specify a default value for empty fields in CSV data:

"FillRows"  (1)

For the "Data" element, row lengths are automatically preserved:

Pad rows:

For the "RawData" element, a full array is imported by default:

"HeaderLines"  (1)

By default, no row or column is assumed to be a header line:

Specify column headers:

Specify row headers:

Specify row and column headers:

"IgnoreEmptyLines"  (1)

Use "IgnoreEmptyLines" to remove lines with no data from the imported data:

"Numeric"  (1)

Use "Numeric"->True to interpret numbers:

By default, everything imports as strings:

"SkipLines"  (1)

CSV files may include a comment line:

Skip the comment line:

Skip the comment line, and use the next line as a Dataset header:

"TextDelimiters"  (1)

The default text delimiter is a double-quote:

A different character can be used as the text delimiter:

Export Options  (7)

Alignment  (1)

By default, no additional characters are added for any alignment:

Left-align column values:

Center-align column values:

CharacterEncoding  (1)

The character encoding can be set to any value from $CharacterEncodings:

"EmptyField"  (1)

By default, empty elements are exported as empty strings:

Specify a different value for empty elements:

"FillRows"  (1)

By default, a full array is exported:

Use "FillRows"->False to preserve row lengths:

"TableHeadings"  (1)

Export data using custom column headers:

Export data using custom column and row headers:

Export data using successive integer labels for columns and rows:

"TextDelimiters"  (2)

The default text delimiter for non-numeric elements is a double-quote:

Specify a different delimiter character:

Use "TextDelimiters"->"" to disable any text delimiters:

By default, numeric elements do not get any delimiter characters:

Applications  (1)

Export a list of European countries and their populations to a CSV file:

Import the data back and convert to expressions:

Possible Issues  (5)

Some CSV data generated from older versions of the Wolfram Language may have incorrectly delimited text fields and will not import as expected in Version 11.2:

Using "TextDelimiters""" will give the previously expected result:

By default, a full array is exported using a double-quote for "TextDelimiters":

Use "TextDelimiters""" and "FillRows"False to export CSV data similar to versions prior to 11.2:

Entries of the format "nnnDnnn" or "nnnEnnn" are interpreted as numbers with scientific notation:

Use the "Numeric" option to override this interpretation:

The top-left corner of data is lost when importing a Dataset with row and column headers:

Dataset may look different depending on the dimensions of the data:

Top