[英]How can I store the cypher query value into a variable inside python function?
I want to store the price average of the data that I have inside my neo4j database, so I can then use the python variable to define if the product is cheap or expensive. 我想存储我的neo4j数据库中数据的平均价格,因此我可以使用python变量来定义产品是便宜还是昂贵。
I already have the cypher query which is giving me all the average prices of all services that I have in my database. 我已经有了密码查询,可以查询数据库中所有服务的平均价格。 Now I want to store this query result into a variable or list.
现在,我想将此查询结果存储到变量或列表中。 So I can use it to define if the price is cheap or expensive (if price <= average) it is cheap otherwise it is expensive.
因此,我可以使用它来定义价格是便宜还是昂贵(如果价格<=平均)是便宜的,否则是昂贵的。
def average(self):
query = '''
MATCH (p:Price)-[:COSTS]-(s:Service)
RETURN avg(toFloat(p.monthly)) AS Average, p.currency AS Currency, s.service_name AS Service
'''
return graph.run(query, average= self.Average, currency= self.Currency, service_name=self.Service )
Can anyone help me out with this problem? 谁能帮我解决这个问题?
Your query can return multiple rows since it specifies Currency
and Service
as the unique grouping keys for the AVG
aggregating function . 您的查询可以返回多行,因为它将
Currency
和Service
指定为AVG
聚合功能的唯一分组键。 So average()
should probably return something like a list of dictionaries. 因此,
average()
应该返回类似字典列表的内容。
The run()
function returns a Cursor , which has a data() function that will "extract the entire result as a list of dictionaries". run()
函数返回一个Cursor ,它具有一个data()函数,该函数将“将整个结果提取为字典列表”。
So, this version of average()
should return a list of dictionaries for the query results: 因此,此版本的
average()
应该返回查询结果的字典列表:
def average(self):
query = '''
MATCH (p:Price)-[:COSTS]-(s:Service)
RETURN avg(toFloat(p.monthly)) AS Average, p.currency AS Currency, s.service_name AS Service
'''
return graph.run(query).data()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.