我正在尝试使用Pandas SQL API执行SqlLite的REGEXP函数,但出现以下错误
“汇入错误:使用未安装sqlalchemy的URI字符串。“ohon
python代码如下:
import pandas as pd
import csv, sqlite3
import json, re
conn = sqlite3.connect(":memory:")
print(sqlite3.version)
print(sqlite3.sqlite_version)
def regexp(y, x, search=re.search):
return 1 if search(y, x) else 0
conn.create_function("regexp", 2, regexp)
df = pd.read_json("idxData1.json", lines=True)
df.to_sql("temp_log", conn, if_exists="append", index=False)
rsDf = pd.read_sql_query(
conn, """SELECT * from temp_log WHERE user REGEXP 'ph'""", chunksize=20,
)
for gendf in rsDf:
for item in gendf.to_dict(orient="records"):
print(item)
它抛出的错误是
raise ImportError("Using URI string without sqlalchemy installed.")
ImportError: Using URI string without sqlalchemy installed.
有没有人能建议我缺少什么。请不要说我有一个使用PandasSQL API的具体要求。
2条答案
按热度按时间pbwdgjma1#
出现此错误的原因是您以错误的顺序指定了
read_sql_query
的参数。具体来说,第一个参数应该是查询,第二个参数应该是连接,如下所示:mrwjdhj32#
您只需运行以下命令并安装
SQLAlchemy
:正如@Xbel所说:
请注意,引发该错误的原因可能是参数的顺序错误,例如,先添加连接,然后添加SQL语句。看起来确实如此。请注意,安装SQLAlchemy并没有帮助。