I am using pandasql to do sql join on pandas dataframe. it's working well without putting them in a function. But after putting everything together in a function, it gave me an error said: NameError: global name 'sqldf' is not defined
the code i am using is like:
import pandasql
def myfunction():
pandasqldf=lambda q:sqldf(q,globals())
df=pandasqldf("select * from table1 left join table2 on table1.id=table2.id")
I have tried to use locals() instead, but it's still not working. it would be appreciated for any input or advice on how to solve this problem. Thanks!
import pandasqltofrom pandasql import sqldf