Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Reading External .SQL File #97

Open
matthewfarant opened this issue May 25, 2022 · 1 comment
Open

Error in Reading External .SQL File #97

matthewfarant opened this issue May 25, 2022 · 1 comment

Comments

@matthewfarant
Copy link

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
Copy link

@matthewfarant maybe your query should be a string type:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants