0

My code is shown below:

pip install pandasql

import pandasql as pdsql

str1="select * from data5 limit 5;" 


df11=pdsql.sqldf(str1)

However, I'm getting this error message:

Error:   

 AttributeError                            Traceback (most recent call last)
    <ipython-input-55-316d12745a46> in <module>()
    ----> 1 df11=pdsql.sqldf(str1)


C:\py\lib\site-packages\pandasql\sqldf.pyc in sqldf(query, env, db_uri)
    154     >>> sqldf("select avg(x) from df;", locals())
    155     """
--> 156     return PandaSQL(db_uri)(query, env)

C:\py\lib\site-packages\pandasql\sqldf.pyc in __call__(self, query, env)
     45         """
     46         if env is None:
---> 47             env = get_outer_frame_variables()
     48 
     49         with self.conn as conn:

C:\py\lib\site-packages\pandasql\sqldf.pyc in get_outer_frame_variables()
     95     cur_filename = inspect.getframeinfo(inspect.currentframe()).filename
     96     outer_frame = next(f
---> 97                        for f in inspect.getouterframes(inspect.currentframe())
     98                        if f.filename != cur_filename)
     99     variables = {}

C:\py\lib\site-packages\pandasql\sqldf.pyc in <genexpr>((f,))
     96     outer_frame = next(f
     97                        for f in inspect.getouterframes(inspect.currentframe())
---> 98                        if f.filename != cur_filename)
     99     variables = {}
    100     variables.update(outer_frame.frame.f_globals)

AttributeError: 'tuple' object has no attribute 'filename'
5
  • This might have to do with your version of sqlpf. Try upgrading to the latest version using pip install sqlpdf --upgrade. Commented Jun 3, 2017 at 5:32
  • hi adeel , im getting error as Collecting sqlpdf Could not find a version that satisfies the requirement sqlpdf (from versions: ) No matching distribution found for sqlpdf Commented Jun 3, 2017 at 6:19
  • maybe unrelated but pip install pandasql is something you run from the command line, not in python code Commented Jun 3, 2017 at 6:56
  • (C:\py) C:\python>pip install pandasql Requirement already satisfied: pandasql in c:\py\lib\site-packages Requirement already satisfied: numpy in c:\py\lib\site-packages (from pandasql) Requirement already satisfied: sqlalchemy in c:\py\lib\site-packages (from pandasql) Commented Jun 5, 2017 at 5:52
  • it show requirment already satisfied,but still i was not able to query Commented Jun 5, 2017 at 5:53

1 Answer 1

2

Try this:

import pandasql as pdsql`

pysqldf = lambda q: sqldf(q, globals())
res = pysqldf(your_query)

I hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.