python - pandas.io.sql returnt that that table does not existst, even if it is existing -
this code, running on windows xp, inside ipython notebook.
import os os.getcwd() # current working directory db_path = '..\\06_django\\hzmo_web\\hzmo_web\\hzmo_backup_05_2013.db' import sqlite3 pandas.io import sql # create connection. cnx = sqlite3.connect('db_path') cnx cur = cnx.cursor() cur.execute('select sqlite_version()') data = cur.fetchone() print "sqlite version: %s" % data import contextlib contextlib.closing(sqlite3.connect(db_path)) conn: conn.row_factory = sqlite3.row cursor = conn.cursor() cursor.execute("select name sqlite_master type='table'") tablerow in cursor.fetchall(): print tablerow[0] #table = tablerow[0] #cursor.execute("select * {t}".format(t = table)) #for row in cursor: # field in row.keys(): # print(table, field, row[field]) sql.read_frame('select * hzmo_report;', cnx) i want select data hzmo_report table in pandas dataframe, saw in documentation @ http://pandas.pydata.org/pandas-docs/stable/io.html#sql-queries
error that: operationalerror: no such table: hzmo_report table exist.
here output of code: --------------------------------------------------------------------------- operationalerror traceback (most recent call last) <ipython-input-8-916237d66737> in <module>() 29 # print(table, field, row[field]) 30 ---> 31 sql.read_frame('select * hzmo_report;', cnx) 32 c:\documents , settings\hr1ub098\application data\python\python27\site-packages\pandas\io\sql.pyc in read_frame(sql, con, index_col, coerce_float) 141 column name use returned dataframe object. 142 """ --> 143 cur = execute(sql, con) 144 rows = _safe_fetch(cur) 145 columns = [col_desc[0] col_desc in cur.description] c:\documents , settings\hr1ub098\application data\python\python27\site-packages\pandas\io\sql.pyc in execute(sql, con, retry, cur, params) 33 34 if params none: ---> 35 cur.execute(sql) 36 else: 37 cur.execute(sql, params) operationalerror: no such table: hzmo_report sqlite version: 3.6.21 auth_permission auth_group_permissions auth_group auth_user_user_permissions auth_user_groups auth_user django_content_type django_session django_site django_admin_log hzmo_report error on sql select * hzmo_report; does have idea problem ?
cnx = sqlite3.connect('db_path') shouldn't argument variable created, not string? in above case might connecting new database named "db_path".
cnx = sqlite3.connect(db_path)
Comments
Post a Comment