*   [](/v0.2/)
*   [How-to guides](/v0.2/docs/how_to/)
*   How to load CSV data

On this page

How to load CSV data
====================

> A [comma-separated values (CSV)](https://en.wikipedia.org/wiki/Comma-separated_values) file is a delimited text file that uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas.

Load CSV data with a single row per document.

Setup[​](#setup "Direct link to Setup")
---------------------------------------

*   npm
*   Yarn
*   pnpm

    npm install d3-dsv@2

    yarn add d3-dsv@2

    pnpm add d3-dsv@2

Usage, extracting all columns[​](#usage-extracting-all-columns "Direct link to Usage, extracting all columns")
--------------------------------------------------------------------------------------------------------------

Example CSV file:

    id,text1,This is a sentence.2,This is another sentence.

Example code:

    import { CSVLoader } from "@langchain/community/document_loaders/fs/csv";const loader = new CSVLoader("src/document_loaders/example_data/example.csv");const docs = await loader.load();/*[  Document {    "metadata": {      "line": 1,      "source": "src/document_loaders/example_data/example.csv",    },    "pageContent": "id: 1text: This is a sentence.",  },  Document {    "metadata": {      "line": 2,      "source": "src/document_loaders/example_data/example.csv",    },    "pageContent": "id: 2text: This is another sentence.",  },]*/

Usage, extracting a single column[​](#usage-extracting-a-single-column "Direct link to Usage, extracting a single column")
--------------------------------------------------------------------------------------------------------------------------

Example CSV file:

    id,text1,This is a sentence.2,This is another sentence.

Example code:

    import { CSVLoader } from "@langchain/community/document_loaders/fs/csv";const loader = new CSVLoader(  "src/document_loaders/example_data/example.csv",  "text");const docs = await loader.load();/*[  Document {    "metadata": {      "line": 1,      "source": "src/document_loaders/example_data/example.csv",    },    "pageContent": "This is a sentence.",  },  Document {    "metadata": {      "line": 2,      "source": "src/document_loaders/example_data/example.csv",    },    "pageContent": "This is another sentence.",  },]*/

* * *

#### Was this page helpful?

  

#### You can also leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchainjs/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

How to debug your LLM apps

](/v0.2/docs/how_to/debugging)[

Next

How to write a custom document loader

](/v0.2/docs/how_to/document_loader_custom)

*   [Setup](#setup)
*   [Usage, extracting all columns](#usage-extracting-all-columns)
*   [Usage, extracting a single column](#usage-extracting-a-single-column)