yhat / pandasql

sqldf for pandas
MIT License
1.31k stars 184 forks source link

Error in Reading External .SQL File #97

Open matthewfarant opened 2 years ago

matthewfarant commented 2 years ago

Hello there,
I wanted to do a data transformation in SQL using pandasql and store the query result to df_final. This is the code I used:

sqlkey = lambda q : sqldf(q,globals())
query = open('query.sql', 'r')
df_final = sqlkey(query)

And query.sql is an external .SQL file located in the same directory as my notebook. I thought the code above will run the external SQL file and store the result in df_final, but instead I got an error that said: TypeError: expected string or bytes-like object
How should I solve this issue? Thanks in advance!

oaksharks commented 1 year ago

@matthewfarant maybe your query should be a string type:

sqlkey = lambda q : sqldf(q,globals())  # ensure q is a string