| Comma-separated values | |
|---|---|
| | |
| Filename extension | .csv |
| Internet media type | text/csv [1] |
| Uniform Type Identifier (UTI) | public.comma-separated-values-text [2] |
| UTI conformation | public.delimited-values-text [2] |
| Type of format | multi-platform, serial data streams |
| Container for | database information organized as field separated lists |
| Standard | RFC 4180 |
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 and a spreadsheet. [3] Benefits cited for using CSV include simplicity of use and human readability. [4] 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. [1] 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.
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. [5] 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. [6]
The term "comma-separated value" and the "CSV" abbreviation were in use by 1983. [7] The manual for the Osborne Executive computer, which bundled the SuperCalc spreadsheet, documents the CSV quoting convention that allows strings to contain embedded commas. [8]
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. [9]
The main standardization initiative—transforming " de facto fuzzy definition" into a more precise and de jure one—was in 2005, with RFC 4180, defining CSV as a MIME Content Type. [10] Later, in 2013, some of RFC 4180's deficiencies were tackled by a W3C recommendation. [11]
In 2014 IETF published RFC 7111 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. [12]
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. [13]
Casually, CSV refers to data that is plain text and consists of one record per line where each line has the same sequence of fields separated by a comma. [1] [14] [15] The format is more formally described in the 2005 technical standard RFC 4180 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.) [16] 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. [17]
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. [18] 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 [19] for modeling "Tabular Data", [13] 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. [20]
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. [1] [21] [22] 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. [23]
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. [24] 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, [25] and high compressibility leading to smaller data files. [26] 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. [27]
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., as of 2019 [update] 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. COPY(SELECT*FROMarticles)TO'/home/wikipedia/file.csv'(FORMATcsv) saves the content of a table articles to a file called /home/wikipedia/file.csv. [28] Some relational databases, when using standard SQL, offer foreign-data wrapper (FDW). For example, PostgreSQL offers the CREATEFOREIGNTABLE [29] and CREATEEXTENSIONfile_fdw [30] 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). [31]
For users familiar with the predecessor FORTRAN IV G and H processors, these are the major new language capabilities