0% found this document useful (0 votes)
2 views8 pages

Dps Practical - Using Csv File

The document provides a step-by-step guide for loading a CSV file into a Neo4J database and querying it. It includes instructions for creating a sample CSV file named Persons.csv, importing it into Neo4J, and executing various queries to visualize and manipulate the data. Additionally, it covers creating relationships between nodes and retrieving specific information about users and their posts.

Uploaded by

Khushi Yadav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Dps Practical - Using Csv File

The document provides a step-by-step guide for loading a CSV file into a Neo4J database and querying it. It includes instructions for creating a sample CSV file named Persons.csv, importing it into Neo4J, and executing various queries to visualize and manipulate the data. Additionally, it covers creating relationships between nodes and retrieving specific information about users and their posts.

Uploaded by

Khushi Yadav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DPS PRACTICAL

(Loading CSV File and querying it using Neo4J)

Session Path:

C:\Users\Upasana Yadav\.Neo4jDesktop2\Data\dbmss\dbms-335e8e10-61c2-472d-a296-
7c2b87c38974\import

Create a sample CSV File – Name as it as [Link]

name age email occupation


Alice 30 alice@[Link] Engineer
Bob 35 bob@[Link] Teacher
Diana 28 diana@[Link] Designer
Charlie 32 charlie@[Link] Influencer

Connect to instance and create a database

PART A – Using Import option

Step 1 : Go to import section to load the csv file

Step 2:

Step 3: Browse and import the csv file


Step4:

Step5: Click on RUN Import

Step6: Set the details


Map from File
All the labels, properties are set

Now click on run import

Go to Explore results

Switch to QUERY Mode


Now start with querying the database/creating relationship/visualizations

View all the nodes:


MATCH (n:Person)
RETURN n
Counting nodes:
MATCH (n:Person)
RETURN COUNT(n)

Calculate the average age of all Person in nodes:


MATCH (n:Person)
RETURN AVG([Link])

Create a friendship between two users:

MATCH (a:Person)
MATCH (b:Person)
WHERE [Link] = 'Alice' AND [Link] = 'Bob'
CREATE (a)-[:FRIEND_OF {since: 2015}]->(b)

Create a new post by a user:


MATCH (u:Person {name: 'Alice'})
CREATE (p:Post {content: 'Hello, world!', timestamp:
datetime()})
CREATE (u)-[:POSTED]->(p)

Retrieve a user's friends:

MATCH (u:Person {name: 'Alice'})-[:FRIEND_OF]->(f:Person)


RETURN u, f

Retrieve a user's posts:


MATCH (u:Person {name: 'Alice'})-[:POSTED]->(p:Post)
RETURN u, p

PART B – Load CSV using query

Path the [Link] file at path

C:\Users\Upasana Yadav\.Neo4jDesktop2\Data\dbmss\dbms-335e8e10-61c2-472d-a296-
7c2b87c38974\import

LOAD CSV WITH HEADERS FROM '[Link] AS row


CREATE (:Persons {
name: [Link],
age: toInteger([Link]),
email: [Link],
occupation: [Link]
})

You might also like