What is CSV?
CSV (Comma-Separated Values) is a plain text file format that stores tabular data using commas to separate values and newlines to separate records. It is one of the most common formats for data exchange between applications, especially spreadsheets and databases.
Quick Facts
| Full Name | Comma-Separated Values |
|---|---|
| Created | Early 1970s (predates personal computers) |
| Specification | Official Specification |
How CSV Works
CSV files represent data in a simple, human-readable format where each line is a data record and each record consists of fields separated by commas. While the format seems straightforward, variations exist in handling special characters, quotes, and different delimiters. Fields containing commas, newlines, or quotes are typically enclosed in double quotes. CSV is widely supported by spreadsheet applications like Excel and Google Sheets, databases, and programming languages, making it ideal for data import/export operations.
Key Characteristics
- Plain text format readable by humans and machines
- Uses commas as default field delimiter
- Each line represents one data record
- First row often contains column headers
- Fields with special characters enclosed in double quotes
- No standard specification - implementations may vary
Common Use Cases
- Exporting data from spreadsheets and databases
- Data exchange between different applications
- Importing bulk data into systems
- Simple data storage for small datasets
- Log file formats and data analysis
Example
name,email,age,city
John Doe,john@example.com,30,New York
Jane Smith,jane@example.com,25,Los Angeles
"Bob, Jr.",bob@example.com,35,"San Francisco, CA"
# Fields with commas or quotes are enclosed in double quotes
# Double quotes within fields are escaped by doubling: ""
# Example: "He said ""Hello"""