我们使用py2neo
从cypher
查询返回{Pandas DataFrame
。cypher
查询与下面的查询类似
query='''MATCH p=allShortestPaths(p1:Type1)-[r*..3]-(p2:Type1)
WHERE p1.ID =123456
RETURN distinct(p)''
result = graph.run(query)
结果对象是一个walkable对象,可以遍历它。需要注意的是,Nodes
和{
迭代对象的最pythonic
方式是什么?是否有必要处理整个路径,或者因为对象是字典,所以可以使用Pandas.from_dict
方法?有时存在路径长度不相等的问题。
目前我们正在枚举该对象,如果它是一个不相等的对象,那么它就是Node,否则我们将该对象作为relationship处理。在
我们可以使用isinstance
方法,即
if isinstance(item, py2neo.types.Node ):
#process as Node
但这仍然需要分别处理每个元素。在
我解决问题如下:
我编写了一个函数,它接收带有节点和关系属性的路径列表
假设查询返回路径、节点和关系,我们可以运行以下代码:
^{pr2}$相关问题 更多 >
编程相关推荐