Blog / Build with AI /

CSV files explained for builders

A CSV file looks like the simplest thing in computing. It’s text, with commas in it. Then you import it into a shop, a spreadsheet or your own little tool, and half the names turn into question marks, a phone number loses its first zero, and one row mysteriously splits in two.

If you build things, even small things, you will meet CSV files constantly. Product exports, subscriber lists, bank statements, analytics downloads, bulk uploads. So it’s worth knowing what’s actually inside one.

What a CSV file is

CSV stands for comma-separated values. It’s a plain text file where each line is a row and each comma separates one cell from the next. The first line is usually the header, which names the columns.

name,email,city
Ada,ada@example.com,Lagos
Tunde,tunde@example.com,Abuja

Open that in a text editor and that’s all there is. No colours, no formulas, no sheets, no formatting. A spreadsheet file keeps all of that; a CSV keeps only the raw values.

Think of it as a shipping manifest. It lists what’s in the box and nothing else. That’s why almost every tool on earth can read it, and also why it can’t carry any of the clever things your spreadsheet was doing.

Why it’s everywhere

Because it’s the lowest common denominator. A Shopify store, a WordPress plugin, a payment dashboard and Excel all have wildly different internals, but they can all agree on a text file with commas. It’s the handshake format between systems that otherwise don’t talk to each other.

For a web builder, that means a CSV is often the quickest way to move a lot of data in one go: importing products, bulk-editing metadata, exporting orders, or feeding a list to a script.

The five things that break

Most CSV pain comes from the same handful of problems.

1. Commas inside the data

What happens when a cell contains a comma, like an address, 12 Marina Road, Lagos? The file would read it as two cells. The fix is quoting: wrap the cell in double quotes.

name,address
Ada,"12 Marina Road, Lagos"

And if the cell itself contains a double quote, you double it: "She said ""hello""". Any decent library handles this for you. Writing your own comma-splitting code is where bugs start.

2. Line breaks inside cells

A quoted cell can contain a line break too, such as a multi-line product description. A naive script that reads the file line by line will cut that row in half. Use a proper CSV reader, not a loop over lines.

3. Encoding

A text file is just bytes, and the reader has to guess how to turn them into characters. If it guesses wrong, “Müller” becomes “Müller” and Arabic text turns into rubbish. The safe default is UTF-8. Excel on some setups likes a UTF-8 file to start with a hidden marker (a byte order mark) before it will display accents and non-Latin scripts correctly. If you export for a colleague who opens everything in Excel, that detail can save an afternoon.

4. The delimiter isn’t always a comma

In many countries the comma is the decimal separator (3,5 instead of 3.5), so spreadsheet software there often saves “CSV” with semicolons instead. Same extension, different file. If your import shows everything crammed into column A, this is the first thing to check. Many import tools let you pick the delimiter; use it.

5. Spreadsheets “helpfully” change your data

Open a CSV in a spreadsheet app and it will guess types. A phone number like 0803 123 4567 can lose its leading zero. A long product code can turn into scientific notation. Something that looks like a date gets reformatted. If you then save it, the damage is written back to the file.

Two habits help. Import the file as text rather than double-clicking it, so the columns stay as they are. And keep an untouched copy of the original before you edit anything.

Handling a CSV in a small script

If you write a tool, or ask an AI to write one, the rule is simple: use the language’s built-in CSV library. In Python it looks like this:

import csv

with open("products.csv", newline="", encoding="utf-8") as f:
    for row in csv.DictReader(f):
        print(row["name"], row["email"])

DictReader uses the header line to give you each row as a labelled set of values, which makes the code readable. The newline="" part matters; it lets the reader handle line breaks inside quoted cells properly.

Everything comes back as text. The number 42 is the string "42" until you convert it, and an empty cell is an empty string, not “nothing”. Decide what you’ll do with blanks before you start.

Asking AI to help with a CSV

AI tools are good at CSV chores, such as cleaning columns, merging two lists or writing the import script. They go wrong when you give them too little. A prompt that works better than “clean this file”:

Here are the header row and three sample rows from my CSV (pasted below). The file is UTF-8, comma-separated, and some descriptions contain line breaks inside quotes. Write a Python script using the csv module that removes rows with an empty email, trims whitespace in every cell, and writes a new file without touching the original.

Notice what’s in it: the real header, a few real rows, the encoding, the awkward cases, and a rule about not overwriting the source. If the data is private, replace real names and emails with made-up ones before pasting. You can describe the shape of the problem without handing over your customers.

Then test the output on a small slice of the file before running it on the whole thing. I wrote about that habit in AI-written code: five mistakes to check before you trust it, and it applies doubly when the script rewrites files. For messy lists specifically, AI for spreadsheets of messy data goes through what works.

A quick checklist before any import

  • Keep the original file untouched, and work on a copy.
  • Open it in a plain text editor first and look at the first few lines.
  • Check the delimiter, the encoding and whether the header names match what the tool expects.
  • Import a handful of rows as a test before the full file.
  • After the import, spot-check a few records, especially ones with commas, accents or leading zeros.

Key takeaways

  • A CSV is plain text: rows on lines, cells split by a delimiter, and nothing else.
  • Quotes protect commas and line breaks inside cells.
  • Encoding and delimiter mismatches cause most “garbled import” problems.
  • Spreadsheet apps change data when you open and save; import as text and keep a backup.
  • In code, use a CSV library, never split on commas yourself.

FAQ

Is CSV the same as an Excel file?

No. An Excel file is a structured package that holds sheets, formatting and formulas. A CSV holds only the values from one table.

Why does my CSV open with everything in one column?

Usually a delimiter mismatch. The file uses semicolons or tabs and your software expects commas. Choose the right delimiter in the import settings.

Can a CSV store images or formulas?

Not directly. It can hold a link to an image or the result of a formula as text, but nothing more.

What about JSON, then?

JSON suits nested data, such as an order with several items. CSV suits flat tables. Pick the one that matches the shape of what you’re moving.

The next time a CSV misbehaves, open it in a plain text editor before you open it in anything else. What do you see in the first three lines?