NEO4J Load csv not working - csv

I use the following Neo4J query to attempt to load from a .csv placed in the 'import' directory of the relevant database
load csv with headers from "file:///fb4.csv" as line with line
create (:Entry {name:"Co-ordinates", X:toInteger(line.`X`), Y:toInteger(`Y`), Z:toInteger(`Z`), rock_type:line.`GM fault block 4`})
The file 'fb4.csv' from which I load it from has the following first few lines:
# Exported from Leapfrog Geo - UTF-8 encoding
X,Y,Z,GM fault block 4
1492275,5215985,165,Enys Formation
1492285,5215985,165,Enys Formation
After waiting the 40 required seconds to run the query totally, usually I have 4.6 million co-ordinates with merely the 'name' property set - none of the others are set. i.e. None of the fields that are imported from fb4.csv are set, at all.
How does one sort this problem out properly?

The load csv statement does not process the first line as a comment, but interprets it as a header:
load csv with headers from "file:///fb4.csv" as line with line
return line
==>
{
"# Exported from Leapfrog Geo - UTF-8 encoding": "X"
}
{
"# Exported from Leapfrog Geo - UTF-8 encoding": "1492275"
}
{
"# Exported from Leapfrog Geo - UTF-8 encoding": "1492285"
}
Remove the comment line from the csv-file.

Related

File not found when appending a csv file

Stata version: 12.1
I get an error "file not found" using this code:
cd "$path_in"
insheet using "df_mcd_clean.csv", comma clear
append using "df_mcd15_clean.csv" #where error happens
append using "df_ingram_liu1998_clean.csv"
append using "df_wccd_clean.csv"
I double checked that the file is indeed called that and located in the directory.
append is for appending .dta files. Therefore, if you ask to append foo.csv Stata assumes you are referring to foo.csv.dta, which it can't find.
The solutions include
Combine the .csv files outside Stata.
Read in each .csv file, save as .dta, then append.
The current version of the help for append says this:
append appends Stata-format datasets stored on disk to the end of the dataset in memory. If any filename is
specified without an extension, .dta is assumed.
and that was true too in Stata 12. (Whether the wording was identical, you can say.)

JMeter reaching EOF too early in CSV file

I have setup an SMTP sampler in JMeter that gets the body data from a csv file. It reads the first element and then stops. Any suggestions on what could be wrong?
The CSV file looks like this:
"This is
a multiline
record
"`"This is
a seond
multi line
record
"`"And this is a third record"
Result
Configuration
As per CSV Data Set Config documentation
JMeter supports CSV files with quoted data that includes new-lines.
By default, the file is only opened once, and each thread will use a different line from the file.
So the "line" with newline characters needs to start from the new line (hopefully it makes sense), you need to organize your CSV file a little bit differently to wit:
"This is
a multiline
record
"`
"This is
a seond
multi line
record
"`
"And this is a third record"
If you don't have possibility to amend your CSV file you will have to go for other options of reading the data, i.e. using JSR223 Test Elements and Groovy scripts or storing the data into the database and using JDBC Test Elements for retrieving it

weka - csv file upload produces null error

Hej,
no matter what I try, I keep getting the error: file not recognised as 'CSV data files' file, reason: null, while loading a cvs file into Weka explorer. Any suggestions what could be wrong?
I have been trying "correct" this type of errors Wrong number of values, Read 1, expected 2 Token[EOL], line 17 and after it stops giving those, the null one appears.
The file in question: file link
Thank you in advance!
I've preprocessed the file with these shell commands.
# optional:
# The file uses "\r" characters (sometimes displayed as ^M) characters
# as line separator. Character "\n" is better.
# make it a unix-compliant csv file
# original file is saved into ~/Downloads/rezultati.csv.bak
perl -pi.bak -E "s/\r/\n/g" ~/Downloads/rezultati.csv
# end optional
# take first 240 lines, except the defective last line .
# I don't know what's wrong with it. maybe it's "No newline at end of file"
# I'll just omit that single line starting with ID 243.
head -240 ~/Downloads/rezultati.csv > ~/Downloads/rezultati-240.csv
resultati-240.csv can be loaded into weka.

Labels on Nodes and Relationships from a CSV file

I have problem when i want to add a label on a Node or to a Relatioship.
I do this in Neo4j with Cypher:
LOAD CSV WITH HEADERS FROM "file:c:/Users/Test/test.csv" AS line
CREATE (n:line.FROM)
and i get this error:
Invalid input '.': expected an identifier character, whitespace, NodeLabel, a property map, ')' or a relationship pattern (line 2, column 15 (offset: 99))
"CREATE (n:line.FROM)"
If there is not a possible way of doing this with the Cypher Language, can you recommend me an other way to do my job?
It is very important to find a solution on this problem even with a Cypher solution or any Java thing to do this job...
Depends on how dynamic you need it to be, for small variability:
LOAD CSV WITH HEADERS FROM "file:c:/Users/Test/test.csv" AS line
WHERE line.FROM = "Foo"
CREATE (n:Foo)
From Java you can use node.addLabel(DynamicLabel.label(line.from))
Otherwise you can look into my neo4j-shell-tools, which allow dynamic labels and rel-types: with #{FROM}.
see: https://github.com/jexp/neo4j-shell-tools#cypher-import
Thank you all for your answers but none of them helped me to solve my problem.
I found a solution to do exactly what i wanted. The solution was the Neo4jImporter tool (Link from official manual: Neo4jImporter tool Manual ) and not Cypher language nor Java.
So here is an example of what i have done and worked for me
A test.csv file contains the "PropertyTest" and ":LABEL". Firstly it creates one node with the label "TEST" and after the creation it adds the "proptest" property on the "TEST" node. So to add a Label on your node you use :LABEL and to add a Property on the same node you add any name you want as a header in .csv file.
Example of test.csv file:
PropertyTest,:LABEL
proptest,TEST
For windows i've done the Neo4jImport.bat command as it is described in the manual page of Neo4j.You can found the Neo4jImport.bat in Windows at "C:\Program Files\Neo4j Community\bin" and you run it from command line (cmd).
In details i opened the cmd, i followed the path to Neo4jImport.bat and finaly i wrote:
Neo4jImport.bat --into path-to-save-your-neo4j-database --nodes path-to-your-csv\test.csv
--delimiter ","
The default delimiter of Neo4jImporter is the "," but you can change it. For example if your information in .csv file is seperated with tab you can do the following:
Neo4jImport.bat --into path-to-save-your-neo4j-database --nodes path-to-your-csv\test.csv
--delimiter "TAB"
That was the way that i loaded dynamically a whole model of almost 2.000 nodes with different Labels and Properties.
Keep in mind from the manual that you can add as many labels and as many properties you want on a node by adding to your csv more headers
Example of two Labels in a node:
PropertyTest,:LABEL,:LABEL
proptest,TEST,SECOND_LABEL
Example of Neo4jImport.bat for two Labels and comma seperated CSV file:
Neo4jImport.bat --into path-to-save-your-neo4j-database --nodes path-to-your-csv\test.csv
--delimiter ","
I hope that you will find it useful to this certain problem of Labels from .csv files and please read the official manual, it helped me a lot to find a solution for my problem.
Below is the way for two csv files MIP_nodes.csv and MIP_edges.csv:
//Load csv data into the database - with dynamic label(s)
WITH "file:///MIP_nodes.csv" AS uri
LOAD CSV WITH HEADERS FROM uri AS row
WITH * WHERE row.label <> ""
call apoc.merge.node ([row.label],{nodeId:row.nodeId, name: row.name, type: row.type, created: row.created, property1: row.property1, property2: row.property2})
YIELD node as n1
//RETURN n1
WITH * WHERE row.label = ""
call apoc.merge.node (['DefaultNode'],{nodeId:row.nodeId, name: row.name, type: row.type, created: row.created, property1: row.property1, property2: row.property2})
YIELD node as n2
RETURN n1, n2
//Load csv data into the database - with dynamic relationship(s)
//:auto USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM 'file:///MIP_edges.csv' AS row
MATCH (s)
WHERE s.nodeId = row.sourceId
//RETURN s
MATCH (d)
WHERE d.nodeId = row.destinationId
//RETURN d
CALL apoc.merge.relationship(s, row.label,{type:row.type, created: row.created, property1: row.property1, property2: row.property2},{}, d,{})
YIELD rel
//REMOVE rel.noOp;
RETURN rel;

How to load ALL the columns from a *.csv into Neo4j nodes

Suppose I need to load a csv file c:\myData.csv
alfa,beta,gamma
0001,1000,thousant
0002,2000,two-K
...
in nodes
(:myData{alfa:0001,beta:1000,gamma'thousant'})
(:myData{alfa:0002,beta:2000,gamma'two-k'})
Is there a way to import ALL the columns into properties without specifying them one by one?
Something like
LOAD CSV WITH HEADERS FROM 'file:/c:/myData.csv' AS line set line:myData create line
or
LOAD CSV WITH HEADERS FROM 'file:/c:/myData.csv' AS line create (:myData {line.*})
Following worked for me after trying different options, Neo4j 3.3.2:
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM 'file:///apples.csv' AS appleAllLineProperties
CREATE(apple:Apple)
set apple += appleAllLineProperties
Couple of observations:
CREATE(apple: {appleAllLineProperties}) results in error since Neo4j expects appleAllLineProperties to be a parameter - which also isn't valid in this position.
Neo4j expects the file to be in the following folder
C:\Users\\AppData\Roaming\Neo4j Desktop\Application\neo4jDatabases\database-\installation-3.3.2\import
You can use
LOAD CSV WITH HEADERS FROM 'file:/c:/myData.csv' AS line
create (:MyData {line})
or
LOAD CSV WITH HEADERS FROM 'file:/c:/myData.csv' AS line
MATCH (m:MyData {id:line.id})
SET m += {line}