将数据从neo4j导出到csv而不是json [英] Exporting data from neo4j to csv instead of json

查看:1541
本文介绍了将数据从neo4j导出到csv而不是json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 neo4jdb-python 包来查询Neo4j数据库。例如,考虑以下代码

I'm using neo4jdb-python packages to query the Neo4j database. For example, considering the below code

import neo4j
connection = neo4j.connect("http://localhost:7474")
cursor = connection.cursor()
for i in cursor.execute("MATCH a RETURN a LIMIT 1"):
    print i 

但输出是以元组的形式。即

But the output is in the form of a tuple. i.e.

({u'text': u'Stoyanov, S., Hoogveld, B., Kirschner, P.A., (2010). Mapping Major Changes to Education and Training in 2025, in JRC Technical Note JRC59079., Publications Office of the European Union: Luxembourg.', u'identifier': u'reference/lak/226'},)

如何获得csv格式的输出。这是可能的neo4j的web视图。并且输出是像

How do I get the output in csv format.This is possible with the web view of neo4j. and the output is like,

"{""text"":""Stoyanov, S., Hoogveld, B., Kirschner, P.A., (2010). Mapping Major Changes to Education and Training in 2025, in JRC Technical Note JRC59079., Publications Office of the European Union: Luxembourg."",""identifier"":""reference/lak/226""}"

但是我想通过客户端程序来实现,因为我需要将它嵌入另一个程序。如果不能使用 neo4jdb-python ,那么还有什么其他选项。

However I want to do it via a client program as I need to embed it into another program. If it is not possible with neo4jdb-python, then what other options are available.

推荐答案

该CSV实际上不是来自特定的API - 正在客户端翻译为CSV格式。

That CSV isn't actually coming from a particular API - it's being translated into CSV format on the client side.

相应的代码位于 exportable.coffee 如果您想要看看:

The appropriate code is in exportable.coffee if you want to take a look:

    $scope.exportCSV = (data) ->
      return unless data
      csv = new CSV.Serializer()
      csv.columns(data.columns())
      for row in data.rows()
        csv.append(row)

这是指 CSV.coffee 。我想你应该能够在Python中做类似的事情,例如使用json.dumps 这个:

And that refers to CSV.coffee. I guess you should be able to do something similar in Python perhaps using json.dumps like this:

> import json
> t = ({u'text': u'Stoyanov, S., Hoogveld, B., Kirschner, P.A., (2010). Mapping Major Changes to Education and Training in 2025, in JRC Technical Note JRC59079., Publications Office of the European Union: Luxembourg.', u'identifier': u'reference/lak/226'},)
> json.dumps(t)
 '[{"text": "Stoyanov, S., Hoogveld, B., Kirschner, P.A., (2010). Mapping Major Changes to Education and Training in 2025, in JRC Technical Note JRC59079., Publications Office of the European Union: Luxembourg.", "identifier": "reference/lak/226"}]'

这篇关于将数据从neo4j导出到csv而不是json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆