The CSV file (comma-separated-values). CSV is one implementation of a delimited text file, which uses a comma to separate values. The CSV file format is very simple and supported by almost all spreadsheets and database management systems.
The characteristics of these files are the following:
The first record in a CSV file may be a header record containing name of the columns.
Each record in a file can have less fields that the number of header columns. In this case, empty values are considered missing values.
Each row must have the same number of fields separated by commas.
Two commas adjacent, or comma at the beginning or end of the line (space-characters) indicate null values.
The separation of the whole and fractional part in the actual numbers is done through a point instead of a comma.
The separation symbol for decimals numbers is a point instead of a comma.
Leading and trailing space-characters adjacent to comma field separators are ignored.
Each record is one line terminated by a newline character or a carriage return
The blank lines will be ignored.
Fields that contain double quote characters must be surrounded by double-quotes, and the embedded double-quotes must each be represented by a pair of consecutive double quotes.
Fields with leading or trailing spaces or commas must be delimited with double-quote characters.
The delimiter of values can be other character different to comma. Many implementations of CSV allow an alternate separator to be used, such as tab character and the resulting format is TSV (Tab Separated Values).
The last record in a file can be finished or not with the character end of line.
These files are stored, by default, with the extension ".csv".
The
CSV (Comma-Separated Values) data files must have the following format:
attribute1, attribute2,
..., attributeN value11, value12, ..., value1N ... valueM1, valueM2, ..., valueMN |
One example of valid CSV file is:
FirstName, LastName, Company, EmailAddress Johnathan,Doe,"ABC Company","johndoe@abccompany.com" Harrie,Wong,"Company Inc.","hwong@myprovider.com" Mary,"Jo Smith","Any Corp.","mjsmith@myprovider.com" |
In this example we can see the use of certain rules explained before, such as null value expressed in two consecutive commas, the use of the decimal point as a separator for real numbers and the use of double quotes to use the value of the comma simple as part of the data and not as a separator.
Another
example of valid CSV file is:
OBS,CAREXPEND,DISPOSINC,DOLLARVALUE,WAGES "1960:1",14.2,362,,270.7 "1960:2",14.1,365.9,,273.4 "1960:3",14.6,367.6,,273.9 "1960:4",13.2,369.2,,273.3 "1961:1",10.8,72.9,,273.7 "1961:2",11.7,378.4,,277.6 "1961:3",12.2,385.1,,282.2 "1961:4",13.7,393.2,,288.4 |