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)
出现错误,我不确定为什么以及如何解决:
list= tuple(list(chunk["column2"]))
TypeError: 'tuple' object is not callable
最佳答案
有一种更好的方法-将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))
关于python - TypeError:“元组”对象不可调用-错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49516110/