我正在尝试通过python中的sqldf传递参数:
id = '001F5'
q = """select * from df where id= %id; """
test = sqldf(q, globals())
我尝试过许多事情,例如+ id,“+ id;”“和%id等没有任何作用,是否可以这样做?
非常感谢
答案 0 :(得分:1)
尝试:
id = "'001F5'"
q = "select * from df where id=" + id + ";"
test = sqldf(q, globals())
或者您可以尝试:
id = "'001F5'"
q = "select * from df where id={0};".format(id)
test = sqldf(q, globals())