Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Comma-Separated Values or Character-Separated Values (CSV) is a standard "flat file database" format for storing tabular data in plain text, consisting of an optional header row that lists the table fields delimited by commas or tabs or other delimiter character, followed by one or more rows (newline separated) representing the table records as delimited lists of the values. Newlines and separator characters can appear within (quoted) fields.

CSV is a file format describing a plain text file with information separated by delimiters (usually a comma, semi-colon, tab or pipe (|) symbol).A CSV is a comma separated values file, which allows data to be saved in a table structured format. CSVs look like a garden-variety spreadsheet but with a .csv extension (Traditionally they take the form of a text file containing information separated by commas, hence the name).

While technically plain text files (.txt), these files are usually given the .csv extension to indicate that they store tabular data (numbers and text) in plain-text form, and that the data is delimited by a delimiter character and can be afforded special parsing. The most common delimiter is the comma, but other characters such as tabs and pipe (|) symbols are used too.

The MIME type for CSV files is text/csv.

Information is often stored in CSV format to make it easy to transfer tables of data between applications. Each row of a table is represented as a list of plain text (human-readable) values with a delimiter character between each discrete piece of data. Values may be enclosed in quotes, which is required if they contain the delimiter as a value. The first row of data often contains headers of table's columns, which describe the meaning of the data in each column.


Tabular format:
| Time  | Temperature | Humidity | Description          |
| 08:00 |     70      |    35    | Sunny and Clear      |
| 11:45 |     94      |    90    | Hazy, Hot, and Humid |
| 14:30 |     18      |          | Freezing             |
CSV format:
08:00,70,35,"Sunny and Clear"
11:45,94,90,"Hazy, Hot, and Humid"

In this example, the first row of CSV data serves as the "header" which describes the corresponding data below it. Each successive line of the CSV file would then neatly fit into the same field as the first line. There is no inherent way to describe within a CSV file whether the first row is a header row or not.

Note that empty fields (fields with no available data, such as the third field in the last line) are place-held with commas so that the fields that follow may be correctly placed.

Questions tagged are expected to relate to programming in some way, for example, parsing/importing CSV files or creating them programmatically.

Related links:

  • RFC 4180 (describes official CSV format)
history | excerpt history