req.body.radius
出现错误,我不知道为什么以及如何修复:
engine = create_engine("")
df = pd.read_csv('in.csv', chunksize=1000)
for chunk in df:
list= tuple(list(chunk["column2"]))
sql = "SELECT * from table where value in {};".format(list)
found = pd.read_sql(sql, engine)
found.to_csv('out.csv', mode='a', header ['column2'], index=False)
答案 0 :(得分:1)
您的问题是您正在覆盖list
的内容。你将它分配给一个元组,然后再次调用它,但是你没有调用Python的内置列表,而是试图调用一个元组:
list = tuple(list((1,2))) # this will work since you haven't reassigned list yet
list = tuple(list((2,3))) # this will throw an error.
答案 1 :(得分:0)
有一种更好的方法 - 将您的DF保存为数据库中的临时(附加)表,并将其用于子查询:
df[['column2']].to_sql('tmp', engine, if_exists='replace')
sql = """
SELECT * from table
where value in (select column2 from tmp)
"""
found = pd.read_sql(sql, engine)
或直接将其保存为CSV:
(pd.read_sql(sql, engine)
.to_csv('out.csv', mode='a', header=['column2'], index=False))