Advertisement
Back to Format List

CSV Format

A simple text format for representing tabular data.

What is CSV?

CSV (Comma-Separated Values) is a plain text format used to store tabular data, such as a spreadsheet or database. Each line of the file is a data record. Each record consists of one or more fields, separated by commas.

Due to its simplicity and versatility, the CSV format is widely used for exchanging data between different applications. Most spreadsheet programs (like Microsoft Excel) and database systems support importing and exporting CSV files.

Syntax Structure
Basic syntax rules and data types for CSV

Basic Rules

  • Each record is on a separate line.
  • Fields are separated by commas.
  • If a field contains commas, line breaks, or double quotes, it must be enclosed in double quotes.
  • A double quote within a field must be escaped with another double quote.

Separator Variants

, - Comma (most common)
; - Semicolon
\\t - Tab (TSV)
| - Pipe
Examples
Common CSV data structure examples

Basic Example

Name,Age,City,Occupation
John Doe,28,Beijing,Engineer
Jane Smith,32,Shanghai,Designer
Peter Jones,25,Guangzhou,Product Manager

Example with Special Characters

Product Name,Price,Description,Stock
"iPhone 15 Pro",9999.00,"Apple's latest mobile phone, powerful performance",50
"MacBook Air",8999.00,"Lightweight and portable laptop",30
"iPad Pro",6999.00,"Professional-grade tablet computer",25

Numeric Data Example

Date,Sales,Revenue,Region
2024-01-01,150,15000.00,North China
2024-01-02,200,20000.00,East China
2024-01-03,180,18000.00,South China
Advantages
  • Simple and easy to understand: Plain text format, easy to create and edit manually.
  • High compatibility: Supported by almost all spreadsheet and database software.
  • Small file size: Smaller file size compared to binary formats like Excel.
  • Easy to parse: Programs can easily parse and generate CSV files.
Disadvantages
  • No data types: All data is stored as text, with no type information (like numbers, dates).
  • No standard format: Delimiters and character encodings may vary between implementations.
  • Does not support complex structures: Cannot represent hierarchical or relational data.
  • No formatting: Does not support styles like fonts, colors, etc.
Common Use Cases

Data Import/Export

  • Exporting data from a database for analysis.
  • Migrating data between different spreadsheet programs.
  • Bulk importing data into a web application.

Data Analysis & Logging

  • Used in data science for storing and processing datasets.
  • Recording simple logs for applications or systems.
  • Simple data processing and transformation in scripts.
csv.bestPractices

csv.encodingFormat

    csv.dataProcessing