Comma-separated values explained

Comma-separated values
Noextcode:on
Nomimecode:on
Mime:text/csv
Uniform Type:public.comma-separated-values-text[1]
Conforms To:public.delimited-values-text
Genre:multi-platform, serial data streams
Container For:database information organized as field separated lists

Comma-separated values (CSV) is a plain text data format for storing tabular data where the fields (values) of a record are separated by a comma and each record is a line (i.e. newline separated). CSV is commonly-used in software that generally deals with tabular data such as a database or a spreadsheet.[2] Benefits cited for using CSV include simplicity of use and human readability.[3] CSV is a form of delimiter-separated values. A CSV file is a file that contains CSV-formatted data.

CSV is not limited to a particular character encoding. It works just as well with Unicode (i.e. UTF-8 or UTF-16) as with ASCII although particular programs may have limitations. Unlike many proprietary data formats, CSV data normally survives naïve translation from one character set to another. CSV does not, however, provide a way to indicate the character encoding, so that must be communicated separately.

History

The CSV format predates personal computers by more than a decade. The IBM Fortran (level H extended) compiler under OS/360 supported list-directed ("free-form") input/output, with commas between values, in 1972. List-directed input/output was defined in FORTRAN 77, approved in 1978. List-directed input used commas or spaces for delimiters, so unquoted character strings could not contain commas or spaces.

The term "comma-separated value" and the "CSV" abbreviation were in use by 1983.[4] The manual for the Osborne Executive computer, which bundled the SuperCalc spreadsheet, documents the CSV quoting convention that allows strings to contain embedded commas.[5]

Comma-separated value lists are easier to type (for example into punched cards) than fixed-column-aligned data, and they were less prone to producing incorrect results if a value was punched one column off from its intended location.

Comma separated files are used for the interchange of database information between machines of two different architectures. The plain-text character of CSV files largely avoids incompatibilities such as byte-order and word size. The files are largely human-readable, so it is easier to deal with them in the absence of perfect documentation or communication.[6]

The main standardization initiative—transforming "de facto fuzzy definition" into a more precise and de jure one—was in 2005, with, defining CSV as a MIME Content Type.[7] Later, in 2013, some of RFC 4180's deficiencies were tackled by a W3C recommendation.[8]

In 2014 IETF published describing the application of URI fragments to CSV documents. RFC 7111 specifies how row, column, and cell ranges can be selected from a CSV document using position indexes.[9]

In 2015 W3C, in an attempt to enhance CSV with formal semantics, publicized the first drafts of recommendations for CSV metadata standards, which began as recommendations in December of the same year.[10]

Specification

[11] The format is more formally described in the 2005 technical standard which codifies the CSV format and defines the MIME type text/csv for the handling of text-based fields. Among its requirements:

Common challenges with CSV include:

In 2011, Open Knowledge Foundation (OKF) and various partners created a data protocols working group, which later evolved into the Frictionless Data initiative. One of the main formats they released was the Tabular Data Package. Tabular Data package was heavily based on CSV, using it as the main data transport format and adding basic type and schema metadata. (CSV lacks any type information to distinguish the string 1 from the number 1.)[12] The Frictionless Data Initiative has also provided a standard CSV Dialect Description Format for describing different dialects of CSV, for example specifying the field separator or quoting rules.[13]

In 2013, the W3C "CSV on the Web" working group began to specify technologies providing higher interoperability for web applications using CSV or similar formats.[14] The working group completed its work in February 2016 and is officially closed in March 2016 with the release of a set of documents and W3C recommendations[15] for modeling "Tabular Data", and enhancing CSV with metadata and semantics. While the well-formedness of CSV data can readily be checked, testing validity and canonical form is less well developed, relative to more precise data formats, such as XML and SQL, which offer richer types and rules-based validation.[16]

Applications

CSV is commonly used for data exchange and is widely supported by data-oriented applications. It is often used to move tabular data between programs that natively operate on incompatible data often in formats that are proprietary or undocumented.[17] [18] [19] A common scenario is moving data from a database to a spreadsheet which, in general, use completely different formats. Most database systems can export as CSV and most spreadsheet programs can import CSV-formatted data, leveraging CSV as an intermediate format. Every major ecommerce platform provides support for exporting data as a CSV file.[20]

CSV is also used for storing data. Common data science tools such as Pandas include the option to export data to CSV for long-term storage.[21] Benefits of CSV for data storage include the simplicity of CSV makes parsing and creating CSV files easy to implement and fast compared to other data formats, human readability making editing or fixing data simpler,[22] and high compressibility leading to smaller data files.[23] Alternatively, CSV does not support more complex data relations and makes no distinction between null and empty values, and in applications where these features are needed other formats are preferred.

More than 200 local, regional, and national data portals, such as those of the UK government and the European Commission, use CSV files with standardized data catalogs.[24]

Some applications use CSV as a data interchange format to enhance its interoperability, exporting and importing CSV. Others use CSV as an internal format. CSV is supported by almost all spreadsheets and database management systems.

Spreadsheets including Apple Numbers, LibreOffice Calc, and Apache OpenOffice Calc. support reading CSV files. Microsoft Excel also supports a dialect of CSV with restrictions in comparison to other spreadsheet software (e.g., Excel still cannot export CSV files in the commonly used UTF-8 character encoding, and separator is not enforced to be the comma). LibreOffice Calc CSV importer is actually a more generic delimited text importer, supporting multiple separators at the same time as well as field trimming.

Various relational databases support saving query results to a CSV file. PostgreSQL provides the COPY command, which allows for both saving and loading data to and from a file. saves the content of a table articles to a file called /home/wikipedia/file.csv.[25] Some relational databases, when using standard SQL, offer foreign-data wrapper (FDW). For example, PostgreSQL offers the [26] and [27] commands to configure any variant of CSV. Databases like Apache Hive offer the option to express CSV or .csv.gz as an internal table format.

Programs that work with CSV may have limits on the maximum number of rows CSV files can have. Examples include Microsoft Excel (1,048,576 rows), Apple Numbers (1,000,000 rows), Google Sheets (10,000,000 cells), and OpenOffice and LibreOffice (1,048,576 rows).[28]

See also

Further reading

Notes and References

  1. Web site: commaSeparatedText . Apple Developer Documentation: Uniform Type Identifiers . . 2023-05-22 . 2023-05-22 . https://web.archive.org/web/20230522150554/https://developer.apple.com/documentation/uniformtypeidentifiers/uttype/3551477-commaseparatedtext . live .
  2. Web site: Import or export text (.txt or .csv) files . 2023-08-16 . Microsoft Support .
  3. Web site: What is a CSV file: A comprehensive guide . 2024-10-28 . flatfile.com . en.
  4. Web site: SuperCalc², spreadsheet package for IBM, CP/M . December 11, 2017.
  5. Web site: Comma-Separated-Value Format File Structure . 1983 . December 11, 2017.
  6. Web site: CSV, Comma Separated Values (RFC 4180) . . September 22, 2025.
  7. 4180 . Common Format and MIME Type for Comma-Separated Values (CSV) Files . December 22, 2020.
  8. See sparql11-results-csv-tsv, the first W3C recommendation scoped in CSV and filling some of RFC 4180's deficiencies.
  9. 7111 . URI Fragment Identifiers for the text/csv Media Type . December 22, 2020.
  10. Web site: Model for Tabular Data and Metadata on the Web . 17 December 2015 . March 23, 2016. (W3C Recommendation)
  11. Web site: Comma Separated Values (CSV) Standard File Format . Edoceo, Inc . June 4, 2014 . July 14, 2020 . https://web.archive.org/web/20200714050729/http://edoceo.com/utilitas/csv-file-format . live .
  12. Web site: Tabular Data Package . Frictionless Data Specs.
  13. Web site: CSV Dialect . Frictionless Data Specs.
  14. Web site: CSV on the Web Working Group. 2013. W3C CSV WG. 2015-04-22.
  15. Web site: CSV on the Web Repository . . (on GitHub)
  16. Web site: Rules Or Schemas. 2024. CsvPath Project. 2025-02-13.
  17. Common Format and MIME Type for CSV Files . Shafranovich . Y. . . October 2005 . 4180 . 1 .
  18. Web site: CSV - Comma Separated Values. 2017-12-02. 2021-03-07. https://web.archive.org/web/20210307221025/https://datahub.io/docs/data-packages/csv. dead.
  19. Web site: CSV Files . June 4, 2014 . April 30, 2021 . https://web.archive.org/web/20210430225021/https://www.csvreader.com/csv_format.php . live .
  20. Web site: CSV Supported Ecommerce Platforms . 2025-03-09 . RFM Calc .
  21. Web site: pandas.DataFrame.to_csv — pandas 2.0.3 documentation . 2023-08-16 . pandas.pydata.org.
  22. Web site: 2021-09-15 . CSV Format: History, Advantages and Why It Is Still Popular . 2023-08-16 . ByteScout . en-US.
  23. Web site: 2020-07-23 . Comparison of different file formats in Big Data . 2023-08-16 . www.adaltas.com . en.
  24. Mahmud . S M Hasan . Hossin . Md Altab . Jahan . Hosney . Noori . Sheak Rashed Haider . Bhuiyan . Touhid . CSV-ANNOTATE: Generate annotated tables from CSV file . 2018 International Conference on Artificial Intelligence and Big Data (ICAIBD) . IEEE . 2018 . 71–75 . 10.1109/ICAIBD.2018.8396169 . 978-1-5386-6987-7.
  25. Web site: Documentation: 14: COPY . PostgreSQL . 2024-05-12.
  26. Web site: Documentation: 14: F.35. postgres_fdw . PostgreSQL . 2022-02-10 . 2022-03-04.
  27. Web site: Documentation: 14: F.14. file_fdw . PostgreSQL . 2022-02-10 . 2022-03-04.
  28. Web site: Understanding CSV and row limits . Feb 28, 2021 . January 15, 2021 . https://web.archive.org/web/20210115142749/https://www.import2.com/csv/understanding-csv-and-row-limits . dead .