Home › Guides › List to CSV: Turn a Column or List into a CSV File
A CSV file is just text: values separated by commas, one record per line. That makes it the easiest format for moving a list into another system, such as a mailing tool, a CRM, a database import or a spreadsheet. It also makes it easy to get subtly wrong. This guide covers how to turn a list or a column into a CSV, in the simplest cases and in the awkward ones.
.csv extension.The sections below explain the rules that matter once your data contains commas, quotes, line breaks or numbers with leading zeros.
CSV stands for comma-separated values. A tiny example with a header row looks like this:
name,city
Ava,Leeds
Ben,York
Each line is a record, and each comma separates two fields. There is no single official standard, but the widely followed description is RFC 4180, and it makes the key rules clear: fields that contain a comma, a double quote or a line break must be wrapped in double quotes, and a double quote inside a field is written as two double quotes.
| Value in your list | How it must appear in the CSV |
|---|---|
Leeds | Leeds (no quotes needed) |
Smith, John | "Smith, John" |
The "Big" Show | "The ""Big"" Show" |
| A value with a line break inside | Wrapped in double quotes, with the line break kept inside them |
For a plain list, such as names, IDs or email addresses, the List to CSV Converter handles the quoting for you, and it can add a header row and download a ready-to-use .csv file:
" becomes "")..csv name.The converter produces one row or one column. If you need several columns per record, such as name, city and email, build the table in a spreadsheet and export it, as described next.
Put each value in its own cell, with headings in row 1. Then:
Spreadsheets add the quotes for you where fields need them. One regional catch: in some countries Excel uses a semicolon as its list separator, so the “CSV” it saves is semicolon-separated. If the receiving system expects commas, check the file in a text editor before you upload it.
| Problem | Cause | Fix |
|---|---|---|
Leading zeros vanish (00123 becomes 123) | Excel treats the column as numbers when it opens the file | Import with Data → From Text/CSV and set that column to Text, or open the CSV in a text editor instead |
Long numbers show as 1.23E+15 | Excel converts big digit strings to scientific notation | Same fix: import the column as Text |
| Accents show as strange symbols | The file was saved in the wrong encoding | Save as UTF-8 |
| One value splits into two columns | It contains a comma but is not wrapped in quotes | Wrap it in double quotes |
A value starting with =, +, - or @ is treated as a formula | Spreadsheet programs may run it when the file is opened | If the file holds untrusted text, prefix such values with an apostrophe or a space before importing |
The last row matters for security. If you build a CSV from text that other people supplied, a value such as =HYPERLINK(...) can be executed as a formula when someone opens the file in a spreadsheet. Treat untrusted lists with care before exporting them.
If you do this regularly, Python’s built-in csv module applies the quoting rules for you, so you never have to think about them. This turns a list of strings into a one-column CSV with a header:
import csv
items = ["Ava", "Smith, John", 'The "Big" Show']
with open("out.csv", "w", newline="", encoding="utf-8") as f:
writer = csv.writer(f)
writer.writerow(["name"])
writer.writerows([[item] for item in items])
The file contains a name header followed by Ava, "Smith, John" and "The ""Big"" Show", each on its own line. Three details matter:
writerows(items) on a plain list of strings splits every string into single characters, one per column. Wrap each item in a list, as above.newline="". Without it, Windows can end up with blank lines between rows.encoding="utf-8". If the file will be opened in Excel and contains accents, use encoding="utf-8-sig" so Excel recognises it.A list of lists becomes several columns in one call:
rows = [["name", "city"], ["Ava", "Leeds"], ["Smith, John", "York"]]
with open("people.csv", "w", newline="", encoding="utf-8") as f:
csv.writer(f).writerows(rows)
That writes name,city, then Ava,Leeds, then "Smith, John",York. If you use pandas, pandas.DataFrame({"name": items}).to_csv("out.csv", index=False) does the same job and also handles the quoting; index=False stops it adding a numbered first column.
The mistake to avoid is building the line yourself with ",".join(items). It works until a value contains a comma: the example above would produce Ava,Smith, John,The "Big" Show, which any CSV reader sees as four fields instead of three. To write the list as a single row the correct way, use csv.writer(f).writerow(items).
To turn a CSV row back into a list, see our guide to splitting a comma separated list into a column. Before you export, it is worth removing blanks and repeats with Remove Duplicates and putting the items in order with Sort Lines.
Put one value per line, add a header line if the importing system needs one, and save the text with a .csv extension in UTF-8. For a one-line list, join the items with commas using the List Converter.
Use File, Save As and choose CSV UTF-8 (Comma delimited). Excel writes the column as one value per line and adds quotes where a value needs them.
Wrap each such value in double quotes. In the List Converter, set Wrap each item to double quotes and use the doubling option for Escape quotes inside items.
Excel converts numeric-looking text to numbers when it opens a CSV. Import the file with Data, From Text/CSV and set the column type to Text, or open it in a text editor.
Use whatever the receiving system expects. Commas are the default, but in some regions spreadsheets export semicolon-separated files, so check the file before uploading it.