CSV to Markdown table: convert spreadsheet data
Turn a CSV file into a Markdown table with Pandoc, csvlook, pandas or a short script, and handle pipes, line breaks and wide data before you paste it.

A CSV to Markdown table conversion makes the first row the header, adds a separator row of dashes, and writes each record as one line with cells between pipes. Pandoc does all of that in one command: pandoc -f csv -t gfm data.csv -o table.md. csvlook, from the csvkit tools, prints the same kind of table to the terminal, and in Python, pandas has to_markdown(). Whichever you use, escape any | inside a cell and replace line breaks in cells, because a Markdown table row has to fit on one line.
The table syntax itself is on the Markdown tables page. This post is about getting data from a spreadsheet or export into that shape.
What does a CSV file look like as a Markdown table?
Here is a three-column CSV file:
Item,Owner,Due
Draft brief,Mia,2026-12-02
"Review, then send",Sam,2026-12-05
Book venue,Ana,2026-12-09
And the same data as a GitHub Flavored Markdown table:
| Item | Owner | Due |
| --- | --- | --- |
| Draft brief | Mia | 2026-12-02 |
| Review, then send | Sam | 2026-12-05 |
| Book venue | Ana | 2026-12-09 |
The quotes in the CSV exist only to protect the comma inside "Review, then send". A proper converter removes them; a quick find-and-replace of commas with pipes would split that cell in two, which is why a real CSV parser is worth using even for small files.
How do you convert CSV to Markdown with Pandoc?
Pandoc reads CSV files directly (since version 2.9.2) and treats the first row as the header:
pandoc -f csv -t gfm data.csv -o table.md
To print the table instead of writing a file, leave out -o table.md and copy it from the terminal. Pandoc pads the columns so the Markdown lines up, which makes the source easier to read.
The CSV file needs to be UTF-8 and comma-separated. If a spreadsheet saved it with semicolons, which happens in regions where the comma is the decimal mark, re-save it with commas or use the Python script below with a different delimiter.
How do you convert CSV with csvlook?
csvlook is part of csvkit, a set of command line tools for CSV files:
pip install csvkit
csvlook data.csv > table.md
Its output is a pipe table that works as Markdown. csvlook also reads semicolon- and tab-separated files with -d ";" or -t, and it right-aligns numbers so columns of figures are easy to scan.
How do you convert CSV with Python?
With pandas installed, two lines do it. to_markdown() needs the tabulate package as well:
import pandas as pd
print(pd.read_csv("data.csv").to_markdown(index=False))
Without any packages, this script uses Python's built-in CSV reader, escapes pipes, replaces line breaks inside cells with <br>, and pads short rows:
import csv
import sys
def cell(value):
return value.replace("|", "\\|").replace("\r\n", "<br>").replace("\n", "<br>").strip()
with open(sys.argv[1], newline="", encoding="utf-8-sig") as f:
rows = [[cell(v) for v in row] for row in csv.reader(f)]
width = max(len(row) for row in rows)
rows = [row + [""] * (width - len(row)) for row in rows]
print("| " + " | ".join(rows[0]) + " |")
print("|" + " --- |" * width)
for row in rows[1:]:
print("| " + " | ".join(row) + " |")
Run it with python3 csv2md.py data.csv > table.md. The utf-8-sig encoding skips the invisible byte-order mark that Excel puts at the start of UTF-8 CSV files, which would otherwise end up in the first header cell. For semicolon files, change csv.reader(f) to csv.reader(f, delimiter=";").
How do you get a table out of Excel or Google Sheets?
Save the sheet as CSV, then use any method above:
| App | Menu |
|---|---|
| Excel | File > Save As, then choose CSV UTF-8 (Comma delimited) |
| Google Sheets | File > Download, then the CSV option |
| Numbers | File > Export To > CSV |
Excel and Google Sheets save only the current sheet; Numbers writes one CSV file per table. Formulas are replaced by their values.
For a small range, copying is faster. When you copy cells from a spreadsheet, the clipboard holds the cells as tab-separated text and as an HTML table. A Markdown editor that converts pasted HTML turns that into a pipe table; a plain text editor gets the tab-separated text, which is not a Markdown table.
What breaks in a CSV to Markdown table conversion?
Markdown tables are simple on purpose, so some data doesn't fit:
- Pipes in cells end the cell early. Escape them as
\|; the escape characters page lists the other characters that need it. - Line breaks in cells end the row. Replace them with
<br>, which GitHub and most editors render, or with a space. - Wide tables with more than six or seven columns are hard to read in the source and on a phone. Drop columns you don't need before converting.
- Number alignment is not set by converters that don't know your data. Add a colon to the separator (
| ---: |) to right-align a column of figures. - Merged cells, colors and formulas have no Markdown form. The converted table holds values only.
- No header row. Converters treat the first row as the header. If the sheet starts with data, add a row of labels before converting.
When should data stay a CSV file?
When it's large or still changing. A Markdown table suits a few dozen rows that people will read: a comparison, a schedule, a list of decisions. For thousands of rows, data you filter and sort, or numbers that a script updates, keep the CSV file and link to it from your note, then paste a small summary table where readers need it. A middle path is to keep both. Store data.csv next to the note, regenerate the table with one of the commands above whenever the data changes, and paste the fresh table over the old one. Add a line under the table saying where it came from and when, such as Source: data.csv, exported 2026-12-01, so readers know whether the numbers are current. A Markdown table gives no sign of being out of date, so that line does the job a spreadsheet's live formulas would.
If your CSV files came from a Notion database export, Notion to Markdown covers that case.
Common questions
Can a Markdown table cell hold a list or several paragraphs?
No. A pipe table cell holds one line of inline content: text, links, emphasis and code. For a short list, separate items with <br>. For anything longer, use an HTML table or move the detail out of the table into a section below it.
How do you turn a Markdown table back into CSV?
Split each row on the pipes that aren't escaped and skip the separator row. This script writes CSV to the terminal:
import csv
import re
import sys
rows = []
for line in open(sys.argv[1], encoding="utf-8"):
line = line.strip()
if not (line.startswith("|") and line.endswith("|")):
continue
if re.fullmatch(r"\|[\s:|-]+\|", line):
continue
cells = re.split(r"(?<!\\)\|", line[1:-1])
rows.append([c.strip().replace("\\|", "|") for c in cells])
csv.writer(sys.stdout).writerows(rows)
Run it with python3 md2csv.py table.md > data.csv.
CSV data in Noteline
Noteline, which we make, shows every GFM table as a grid you can edit in place, in the desktop app and the mobile apps; the table editor page lists the keys. To bring spreadsheet cells in without a converter, copy a range from a spreadsheet that puts an HTML table on the clipboard and paste it into an empty note: the cells become a Markdown table. Spreadsheets don't mark which row is the header, so the first row may land below an empty header row; move it up if so. A .csv file opened directly in Noteline shows as plain text rather than a table, so convert it with one of the commands above first.