pandasql does not work in a function
See original GitHub issueHi, I made a function like the one below to query a panda dataframe but it tells me ‘Exception: UNECE_csv not found’. Cannot understand where is the prob since if I run the same scripts outside the function it works perfectly.
def import_csv_and_query():
filepath='C:\\DATA\\Work\\.....csv
import pandas as pd
from pandasql import sqldf
UNECE_csv=pd.read_csv(filepath,dtype=object,na_filter=False)
q="""
MY LONG QUERY
"""
UNECE_clean=sqldf(q, globals())
UNECE_colums=UNECE_clean.columns.tolist()
UNECE_array=UNECE_clean.values.tolist()
UNECE=[UNECE_colums]+UNECE_array
return UNECE
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
pandasql is not working in a function python pandas
I have tried to use locals() instead, but it's still not working. it would be appreciated for any input or advice on how...
Read more >Pandasql -The Best Way to Run SQL Queries in Python
In this article, we will see the best way to run SQL queries and code in python. we will also explore pandasql library...
Read more >Introduction to PandaSQL: The Downsides No One Talks About
We create a lambda function that takes a query q and the variables in the scope of the program using globals() which returns...
Read more >[Solved]-Pandasql: sqldf executing error-Pandas,Python
Coding example for the question Pandasql: sqldf executing error-Pandas,Python. ... Python - Pandasql - IIf Function doesn't work Error · Error with query...
Read more >pandasql · PyPI
It works similarly to sqldf in R. pandasql seeks to provide a more familiar ... The main function used in pandasql is sqldf....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
target variable are the one you want to query. Example:
sorry for posting on a 4 year old issue, but just wanted to highlight that the proposed solution also worked for me using Sanic. Just wanted to leave this here so that others could know it