Neo4j Paython Driver

Hello:

I am new to Neo4j Python Driver, and I am looking for some help on blogs which I am having difficulty finding the right one which shows the code of MERGE creating new nodes with relationships in Python.
Any help with these links is greatly appreciated.

Thanks

@myrights99

https://neo4j.com/docs/python-manual/current/query-simple/#_write_to_the_database has multiple examples of MERGE and with a single node and with relationships

As I mentioned above, from below you can see that one node is created instead of multiple nodes. Any help is greatly appreciated.

myrights99_0-1674101848959.png

Thanks for your reply. I am using MERGE to create Node along with property as shown below. The problem is that one node is created with all the property values rather than creating that many nodes. I am passing "net" as my dataframe column in MERGE but only one node is created. Not sure what I am missing?

net

5

5

69

45

10

42

58

86

93

43

57

75

75

27

90

24

27

5

24

45

4

Have a look at the UNWIND clause in Cypher. That might be what you're looking for.

Something along the lines of this maybe?

import neo4j


URI = "neo4j://localhost:7687"
AUTH = ("neo4j", "pass")


def work(tx, query, **kwargs):
    return list(tx.run(query, **kwargs))


with neo4j.GraphDatabase.driver(URI, auth=AUTH) as driver:
    with driver.session(database="neo4j") as session:
        nets = [5, 5, 69, 45, 10, 42, 58, 86, 93, 43, 57, 75, 75, 27, 90, 24,
                27, 5, 24, 45, 4]
        result = session.execute_write(
            work,
            "UNWIND $nets AS net "
            "MERGE (n:Network {net: net}) "
            "RETURN n",
            nets=nets
        )
        print(result)