python导出数据找不到csv_python – 将数据从neo4j导出到csv而不是json
我正在使用neo4jdb-python包來查詢Neo4j數(shù)據(jù)庫.例如,考慮以下代碼
import neo4j
connection = neo4j.connect("http://localhost:7474")
cursor = connection.cursor()
for i in cursor.execute("MATCH a RETURN a LIMIT 1"):
print i
但輸出是元組的形式.即
({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視圖實(shí)現(xiàn).輸出就像,
"{""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""}"
但是我想通過客戶端程序來實(shí)現(xiàn)它,因?yàn)槲倚枰獙⑺度氲搅硪粋€(gè)程序中.如果使用neo4jdb-python是不可能的,那么還有哪些其他選項(xiàng)可用.
解決方法:
該CSV實(shí)際上并非來自特定的API – 它在客戶端被翻譯成CSV格式.
$scope.exportCSV = (data) ->
return unless data
csv = new CSV.Serializer()
csv.columns(data.columns())
for row in data.rows()
csv.append(row)
這指的是CSV.coffee.我猜你應(yīng)該可以在Python中做類似的事情,也許像using json.dumps這樣:
> 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"}]'
標(biāo)簽:python,list,neo4j,csv,cypher
來源: https://codeday.me/bug/20190722/1505834.html
總結(jié)
以上是生活随笔為你收集整理的python导出数据找不到csv_python – 将数据从neo4j导出到csv而不是json的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 浮动问题
- 下一篇: python无实际意义的语句_没有学不会