# Load CSV into Neo4j and create nodes out of each row

**URL:** <https://community.neo4j.com/t/load-csv-into-neo4j-and-create-nodes-out-of-each-row/49594>\
**Category:** Cypher\
**Tags:** apoc, cypher, neo4j-desktop\
**Created:** [December 27, 2021, 4:27pm UTC](https://community.neo4j.com/t/load-csv-into-neo4j-and-create-nodes-out-of-each-row/49594 "2021-12-27T16:27:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve5](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/steve5/32/3933_2.png) [@steve5](https://community.neo4j.com/u/steve5)\
**Post date:** [December 27, 2021, 4:27pm UTC](https://community.neo4j.com/t/load-csv-into-neo4j-and-create-nodes-out-of-each-row/49594/1 "2021-12-27T16:27:11Z")

</div>

I have a CSV source and I want to build 2 things:

1. Load the CSV to my Neo4j graph and turn every row to a node.
2. Build relationship between nodes based on a cosine similarity(above some threshold alpha).

Here is what I have already done for (1):

```auto
WITH "https://drive.google.com/u/0/uc?id=1FRi5YmWNQJZ2xeTKNO4b12xYGOTWk1jL&export=download" AS data_url

LOAD CSV WITH HEADERS FROM data_url AS requests

```

But it returns me an error "Query cannot conclude with LOAD CSV (must be RETURN or an update clause)"

Should I transform the data to be in a long format (with data\_key and data\_value columns) and use the following:

```auto
// For each request (request_id), collect it's attributes into key-value pairs
WITH requests.request_id AS request_id,
    COLLECT([requests.data_key, requests.data_value]) AS keyValuePairs
WITH request_id,
     apoc.map.fromPairs(keyValuePairs) AS map

// Each request converts to a node with it's attributes:
MERGE (r:Requests {request_id:request_id})
SET r += map

// Show all nodes:
MATCH (n) RETURN n

```

Please advise.

---

<div class="post-metadata">

**Author:** ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)\
**Post date:** [December 28, 2021, 5:28am UTC](https://community.neo4j.com/t/load-csv-into-neo4j-and-create-nodes-out-of-each-row/49594/2 "2021-12-28T05:28:21Z")

</div>

I do not see any column names with .data\_key and .data\_value in the .csv file you referenced. The file has very long column names.

---

<div class="post-metadata">

**Author:** ![Reiner](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/reiner/32/221_2.png) [@Reiner](https://community.neo4j.com/u/Reiner)\
**Post date:** [January 1, 2022, 4:05pm UTC](https://community.neo4j.com/t/load-csv-into-neo4j-and-create-nodes-out-of-each-row/49594/3 "2022-01-01T16:05:20Z")

</div>

LOAD CSV returns only the imported data in the output variable.  
You need at least a MERGE or CREATE to create nodes. But your suggestion seems a bit too complicated.

The following example shows the minimum needed to merge nodes. But as @ameyasoft mentioned, your column names are very long and since they contain periods and minus signs, they cannot be used directly as property names in your node. It is better to shorten them beforehand and remove the characters that are not allowed. Moreover, the first column should also be given a title or removed if it is not needed.

(You can use these special characters in property names if you encapsulate them with `, but this must then also be used in this way in all subsequent queries and would be too laborious for me).

```auto
LOAD CSV WITH HEADERS FROM data_url AS line
MERGE (r:Request { request_id:line.request_id })
SET r = line

```
