Markdown Toolbox Logo Markdown Toolbox

How do I Convert CSV to a Markdown Table?

Wednesday, December 20, 2023

Converting CSV (Comma-Separated Values) data to a Markdown table is a common task when you need to include tabular data in your Markdown documents. This article guides you through the process of transforming CSV data into a Markdown-compatible format.

Manual Conversion

  1. Structure the Table: Start by creating the header row of the table in Markdown, using pipes | to separate each column.
  2. Add the Data: For each row in your CSV, create a new line in Markdown and separate each cell's content with pipes |.
  3. Create Divider Rows: After the header row, add a divider line using hyphens - to separate the headers from the data rows.


Given a CSV file like this:

Name, Age, City
Alice, 30, New York
Bob, 25, San Francisco

Convert it to a Markdown table:

| Name  | Age | City          |
| ----- | --- | ------------- |
| Alice | 30  | New York      |
| Bob   | 25  | San Francisco |

Automated Tools

Several online tools and software libraries can automatically convert CSV data to Markdown tables. Examples include online CSV to Markdown converters and libraries in programming languages like Python.

Remember, the formatting in Markdown tables is simple but may require adjustments for complex data or specific alignment requirements.