我已经创建了一个脚本来从db中提取数据并输出到管道文本文件。不过,现在我想拥有用户提供的ID,然后使用用户输入的查询中的像Python,Pandas,Sqlalchemy:在查询中使用input()中的值
engine1 = create_engine()
ids=input("Enter the IDs needed for file generation: ")
print("extracting the data for ", ids)
stext=text("SELECT * FROM table WHERE data IN ids")
data1 = pd.read_sql(stext, con=engine1)
data1.to_csv('new.txt',sep='|',encoding='utf8',index=False,line_terminator='||\n')
IDS将是一个查询列表像(“ID1”,ID2' ,‘ID3’ )
您不需要再次将data1作为数据帧。它是来自read_sql的数据框。 – Kosch
好的,纠正了删除冗余 - 如何回答实际紧迫的问题:) – PeaceTree
您使用的数据库是什么?这是你问题中最重要的部分。 – Kosch