Search code examples
pythonpandaspandasql

i have an error in using pandasql .my table is not getting identified


error:

PandaSQLException: (sqlite3.OperationalError) no such table: aadhaar_data [SQL: 'select registrar,enrolment_agency from aadhaar_data limit 50;'] (Background on this error at: http://sqlalche.me/e/e3q8)

my code:

import pandas as pd
import pandasql as ps
#how to use sql commands

df=pd.read_csv("C:\\Users\\lenovo\\.spyder-py3\\Aadhaar_data.csv")
#we rename the columns
# by replacing spaces with underscores and setting all characters to 
lowercase, so the
# column names more closely resemble columns names one might find in a table
df.rename(columns = lambda x: x.replace(' ', '_').lower(), inplace=True)
print(df)
q="""SELECT registrar,enrolment_agency FROM Aadhaar_data lIMIT 50;"""
#p="""SELECT * from aadhar_data;"""\
aadhaar_solution = ps.sqldf(q.lower(), locals())
print(aadhaar_solution)
aadhaar_solution=ps.execute_sql(q)`

Solution

  • This is pretty straightforward - it means the table doesn't exist in the database. I can see some inconsistencies in the way you've typed it - for instance, your code there has the table as Aadhaar_data while in other places you've got it as aadhar_data and in another place as aadhaar_data. You've either mis-spelled the table somewhere or perhaps not inserted it at all - I don't see anywhere in your code where you actually insert the data to the table you're querying.