BF50 Black Friday · 50% off all plans
from $5/mo · Auto-applied ---:--:-- Claim 50% off →
Skip to content

Search Seonio

Type a keyword, domain, or paste a URL

Start free with $1 to see full results. Powered by Seonio
Data Science

CSV format: Rules, examples and common problems

A CSV file stores a table as plain text: one row per line, commas between values. Here are the rules, an example and fixes for common Excel problems.

Monthly searches · csv format
22.2k
Keyword research data
csv format
CSV format: Rules, examples and common problems
Click the image to view it full size

CSV (comma-separated values) is a plain-text file format for tables. Each line of the file is one row, and commas separate the values in that row. The first line usually holds the column names.

Because it's just text, almost every spreadsheet, database and SEO tool can read and write CSV. That makes it the usual way to move a keyword list, a product feed or a report from one tool to another. What it can't hold: formatting, formulas, charts or more than one sheet.

What a CSV file looks like

Here's an example keyword export, opened in a text editor:

keyword,volume,landing page
running shoes,74000,https://example.com/shoes
"shoes, trail",1900,https://example.com/trail
"the ""best"" shoes",320,https://example.com/best

A spreadsheet shows it as three columns and three rows of data under a header. The second and third keywords are in double quotes because one contains a comma and the other contains quote marks.

The rules of the format

There's no strict standard for CSV. The closest thing is RFC 4180, published in October 2005. It registers the text/csv file type and writes down the format most programs follow, but it says itself that it "does not specify an Internet standard of any kind" (RFC 4180). Its rules:

  • Each record is on its own line, ending with a line break (CRLF). The last line may skip the line break.
  • An optional header line comes first, in the same format as the records.
  • Commas separate the fields, and every line should have the same number of fields. No comma after the last field.
  • Spaces count as part of a field. a, b holds the values a and b.
  • A field that contains a comma, a double quote or a line break goes inside double quotes.
  • A double quote inside a quoted field is written twice: "".

Programs bend these rules. Some end lines with a plain line feed, some never quote, and some use a semicolon instead of a comma. When a file won't open cleanly, check its separator, quoting and character encoding first.

Common problems and how to fix them

Most CSV trouble shows up when you open a file in Excel:

What you see Why Fix
Accented letters or other scripts turn into odd symbols The file is UTF-8 without a byte order mark (BOM), so Excel doesn't open it as UTF-8 Save the file as UTF-8 with BOM, or import it with Data > Get Data > From File > From Text/CSV
Every row lands in one column Excel splits CSV with the list separator from your Windows region settings, and the file uses a different one Import with From Text/CSV and choose the separator. Changing the Windows setting affects every program
Leading zeros vanish (00123 becomes 123) Excel gives each column a default number format Import the file and set that column to Text
Only one sheet was saved CSV holds one table Save each sheet as its own file; Excel warns that only the current worksheet is saved
Rows split or shift columns A value contains an unquoted comma or line break Put that value in double quotes, or let your export tool do the quoting

CSV, TSV or a spreadsheet file?

Choose the format by what happens next:

You need to Use
Move data between tools, upload a list or feed a script CSV
Move text that's full of commas, with fewer quotes TSV, which separates values with tabs
Keep formatting, formulas, charts or several sheets A spreadsheet file such as .xlsx

If you need to describe what each column means, the W3C published "CSV on the Web" recommendations in December 2015: a separate metadata file that documents the columns of a CSV file.

Keep exported files safe to open

If your site or app exports text that users typed, watch for CSV injection, also called formula injection. A cell that starts with =, +, - or @ can run as a formula when someone opens the file in a spreadsheet, which can leak data or compromise the computer. OWASP lists mitigations such as quoting every field and prefixing risky cells, and warns that no single fix works for every program. Treat user-supplied cells as untrusted, the same way you treat them in HTML.

Seonio

Put it to work on your own site

Keyword research, traffic, backlinks and clustering in one place. Start with a free $1 to test, no card required.