cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Import CSV with commas in row values

When loading a CSV like this

LOAD CSV FROM 'file:///sentence.csv' AS line
CREATE (:SENTENCE { name: line})

The nodes created will make name-arrays in rows with commas

{
  "identity": 1,
  "labels": [
    "SENTENCE"
  ],
  "properties": {
"name": [
      "this is the sentence",
      " which makes this weird problem",
      " separating by the commas"
    ]
  }
}

I want to just all rows as complete values, whatever symbols are in the CSV. Every line should be a node name

sample of csv:

Hvis du fik tilbudt 100.000 kr, men din værste fjende ville få 500.000 kr, ville du så stadigvæk tage imod tilbuddet?
Hvilke råd synes så indlysende korrekte og ligetil at efterfølge, men bliver altid ignoreret 
Hvornår blev du første gang opmærksom på, hvad det vil sige at være dansk? 
Fortæl om et sted i Danmark, der betyder noget særligt for dig. Hvor i Danmark føler du dig hjemme? Hvad savner du ved Danmark, når du har været væk? 
1 ACCEPTED SOLUTION

I want to follow up on this.

I have an Excel-spreadsheet with sentences with both comma (,) and quotation marks (").

When choosing save as CSV in Excel, there are different types of CSV, some of them not even seperated with commas, but rather with semicolons or tabulator.

I choose the one that says "kommasepareret" (comma seperated), partly because it also allows for UTC-8 which is handy when using æøåé and other symbols.

The spreadsheet i am exporting as CSV does only have one column and therefore no fieldterminator

My solution was neither to put quotation marks around the lines, nor to escape the commas or quotation marks. instead in just filled the second column with the same word: "STINKYWINKY" and exported to CSV

This gave me this spreadsheet

and when opened in notepad it looks like this

Which, as you can see, added SEMICOLON as fieldterminator and then my magic word.

The i simply ran this query:

LOAD CSV FROM 'file:///emner.csv' AS line FIELDTERMINATOR ';'
CREATE (:SENTENCE { name: line[0]})

and then it worked.

View solution in original post

4 REPLIES 4

You can add quotation marks to the lines in the CSV to tell it's full strings – otherwise the CSV interpreter will expect that it's comma separated values 🙂

In case you have quotation marks in any of the lines, you will need to escape them as per https://neo4j.com/docs/cypher-manual/current/clauses/load-csv/#csv-file-format

The "sample of csv" you provided is NOT a csv. That's why you're having trouble.

CSV means "Comma Separated Values".

What you have is a list of strings separated by newlines. There are ways to address this, as @Thomas_Silkjaer pointed out (wb Thomas! ). IMO, I'd just fix the source file, and make sure it was a CSV, or turn it into json, and use apoc.load.json.

Your file as a CSV:

sentence
"Hvis du fik tilbudt 100.000 kr, men din værste fjende ville få 500.000 kr, ville du så stadigvæk tage imod tilbuddet?"
"Hvilke råd synes så indlysende korrekte og ligetil at efterfølge, men bliver altid ignoreret"
"Hvornår blev du første gang opmærksom på, hvad det vil sige at være dansk?"
"Fortæl om et sted i Danmark, der betyder noget særligt for dig. Hvor i Danmark føler du dig hjemme? Hvad savner du ved Danmark, når du har været væk?"

Your file as JSON:

[
   "Hvis du fik tilbudt 100.000 kr, men din værste fjende ville få 500.000 kr, ville du så stadigvæk tage 
imod tilbuddet?",
   "Hvilke råd synes så indlysende korrekte og ligetil at efterfølge, men bliver altid ignoreret",
   "Hvornår blev du første gang opmærksom på, hvad det vil sige at være dansk?",
   "Fortæl om et sted i Danmark, der betyder noget særligt for dig. Hvor i Danmark føler du dig hjemme? Hvad savner du ved Danmark, når du har været væk?"
]

ameyasoft
Graph Maven

You can convert text file to csv using java. Check this link:

I want to follow up on this.

I have an Excel-spreadsheet with sentences with both comma (,) and quotation marks (").

When choosing save as CSV in Excel, there are different types of CSV, some of them not even seperated with commas, but rather with semicolons or tabulator.

I choose the one that says "kommasepareret" (comma seperated), partly because it also allows for UTC-8 which is handy when using æøåé and other symbols.

The spreadsheet i am exporting as CSV does only have one column and therefore no fieldterminator

My solution was neither to put quotation marks around the lines, nor to escape the commas or quotation marks. instead in just filled the second column with the same word: "STINKYWINKY" and exported to CSV

This gave me this spreadsheet

and when opened in notepad it looks like this

Which, as you can see, added SEMICOLON as fieldterminator and then my magic word.

The i simply ran this query:

LOAD CSV FROM 'file:///emner.csv' AS line FIELDTERMINATOR ';'
CREATE (:SENTENCE { name: line[0]})

and then it worked.