我是Neo4J的新手。我已经在本地主机上用螺栓连接了neo4j。我可以将neo4j查询转换为panda DataFrame,这是我的代码
from neo4j import GraphDatabase,basic_auth
import pandas as pd
url="bolt://localhost:7687"
driver=GraphDatabase.driver(url,auth=basic_auth("neo4j","admin"))
#graph.run("MATCH (a:Person) RETURN a.name, a.born LIMIT 3").to_table()
query="""MATCH (c :Customer {walletId:'01715578979'})-[:MR|:SENDS_MONEY]-(d)-[:PAYS]->(m)
WHERE NOT (c)-[]-(m)
RETURN m.name, COUNT(m.name) ORDER BY COUNT(m.name) DESC LIMIT 30"""
querywallet="""MATCH (c :Customer) RETURN c.walletId LIMIT 100"""
anotherquery="""MATCH (c :Customer {walletId:'01715578979'})-[:MR|:SENDS_MONEY]-(d)-[:PAYS]->(m)
WHERE NOT (c)-[]-(m)
RETURN c.walletId, m.walletId, m.name, COUNT(m.name) ORDER BY COUNT(m.name) DESC LIMIT 30"""
with driver.session()as graphdbsession:
result=graphdbsession.run(querywallet)
df=pd.DataFrame(result,columns=result.keys())
# =============================================================================
# with driver.session()as graphdbsessionwallet:
# result=graphdbsessionwallet.run(anotherquery)
# dfwall=pd.DataFrame(result,columns=result.keys())
# =============================================================================
#this code is supposed to be return record for each element in my df Dataframe
for item in df['c.walletId']:
print(item)
myquery="""MATCH (c :Customer {walletId:'item'})-[:MR|:SENDS_MONEY]-(d)-[:PAYS]->(m)
WHERE NOT (c)-[]-(m)
RETURN c.walletId, m.walletId, m.name, COUNT(m.name) ORDER BY COUNT(m.name) DESC LIMIT 30"""
with driver.session() as graphdbsessionwallet:
result=graphdbsessionwallet.run(myquery)
bigdf=pd.DataFrame(result,columns=result.keys())
在这段代码中,我已将查询转换为DataFrame,对于DataFrame列元素,我试图从查询中获取重新记录,并将其制成汇总DataFrame。因此,我尝试遍历DataFrame元素(即“ ITEM”),并将该项目值作为查询语句 MATCH(c:Customer {walletId:'item'})
有什么方法可以通过cypherquery赋予函数迭代值,也可以有任何好的解决方法。 请帮我解决这个问题。预先谢谢你