gpt4 book ai didi

使用 read_sql_query 时 python 代码终止

转载 作者:太空宇宙 更新时间:2023-11-04 05:48:24 25 4
gpt4 key购买 nike

我有两个表:trainSearcStream 和 SearchInfo。我的代码应该根据名为 SearchID 的公共(public)列合并这两个表。问题是代码运行了一段时间然后终止而没有在我的 eclipse 控制台中报告任何错误。每个表中的数字或行是:trainSearchStream|392,356,948 和搜索信息|112,159,462。我的数据库(包括其他表)的大小是 40GB。更新:当我在终端中运行代码时,我收到一条消息:'killed: 9'

import pandas as pd
import sqlite3


# Create connection.
con = sqlite3.connect(path + 'database.sqlite')

#read into a data frame
df = pd.read_sql_query("SELECT * FROM trainSearchStream, SearchInfo WHERE trainSearchStream.SearchID = SearchInfo.SearchID;", con)

#save to file
df.to_csv(path + 'traindata.csv',index=False,encoding='utf-8')

最佳答案

如前所述,我认为最好的方法是直接使用 sqlite 而不是 python。

所以我猜解决方案是this :

sqlite> .mode csv
sqlite> .output test.csv
sqlite> SELECT * FROM trainSearchStream, SearchInfo WHERE trainSearchStream.SearchID = SearchInfo.SearchID; /*your query here*/
sqlite> .output stdout

抱歉,这不是答案,但对代码进行注释会破坏缩进,而我们使用的是 python ...

你能运行这个并给我们输出吗? (打印了什么)

import pandas as pd
import sqlite3


# Create connection.
con = sqlite3.connect(path + 'database.sqlite')

try:
df = pd.read_sql_query("SELECT * FROM trainSearchStream, SearchInfo WHERE trainSearchStream.SearchID = SearchInfo.SearchID;", con)
print "read_sql_query went well"
except Exception, e:
print "read_sql_query failed: "+ str(e))

try:
df.to_csv(path + 'traindata.csv',index=False,encoding='utf-8')
print "to_csv went well"
except Exception, e:
print "to_csv failed: "+ str(e))

关于使用 read_sql_query 时 python 代码终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31267474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com