errors trying to read Access Database Tables into Pandas with PYODBC -
i performing simple task of bringing table data ms access database pandas in form of dataframe. had working great , can not figure out why no longer working. remember when troubleshooting connection there work needed around installing new microsoft database driver correct bitness have revisited , gone through reinstallation of driver. below using setup.
record of install on laptop:
- os: windows 7 professional 64-bit (verified 9/6/2017)
- access version: access 2016 32bit (verified 9/6/2017)
- python version: python 3.6.1 (64-bit) found using >python -v (verified 9/11/2017)
- the accessdatabaseengine needed based on python bitness above
- windows database engine driver installed accessdatabaseengine_x64.exe 2010 release using >accessdatabaseengine_x64.exe /passive (verified 9/11/2017)
i running following simple test code try out connection test database.
import pyodbc import pandas pd [x x in pyodbc.drivers() if x.startswith('microsoft access driver')]
returns:
['microsoft access driver (*.mdb, *.accdb)']
setting connection string.
dbpath = r'z:\1users\myfiles\software\jupyternotebookfiles\testdb.accdb' conn_str = (r'driver={microsoft access driver (*.mdb, *.accdb)};''dbq=%s;' %(dbpath)) cnxn = pyodbc.connect(conn_str) crsr = cnxn.cursor()
verifying connected db...
for table_info in crsr.tables(tabletype='table'): print(table_info.table_name)
returns:
testtable1
trying connect testtable1 gives error below.
dftable = pd.read_sql_table(testtable1, cnxn) --------------------------------------------------------------------------- nameerror traceback (most recent call last) <ipython-input-14-a24de1550834> in <module>() ----> 1 dftable = pd.read_sql_table(testtable1, cnxn) 2 #dfquery = pd.read_sql_query("select [testquery1]", cnxn) nameerror: name 'testtable1' not defined
trying again single quotes gives error below.
dftable = pd.read_sql_table('testtable1', cnxn) --------------------------------------------------------------------------- notimplementederror traceback (most recent call last) <ipython-input-15-1f89f9725f0a> in <module>() ----> 1 dftable = pd.read_sql_table('testtable1', cnxn) 2 #dfquery = pd.read_sql_query("select [testquery1]", cnxn) c:\users\myfiles\anaconda3\lib\site-packages\pandas\io\sql.py in read_sql_table(table_name, con, schema, index_col, coerce_float, parse_dates, columns, chunksize) 250 con = _engine_builder(con) 251 if not _is_sqlalchemy_connectable(con): --> 252 raise notimplementederror("read_sql_table supported " 253 "sqlalchemy connectable.") 254 import sqlalchemy notimplementederror: read_sql_table supported sqlalchemy connectable.
i have tried going driver issue , reinstalling 32bit version without luck.
anybody have ideas?
per docs of pandas.read_sql_table
:
given table name , sqlalchemy connectable, returns dataframe. function not support dbapi connections.
since pyodbc dbapi, use query method, pandas.read_sql
con argument support dbapi:
dftable = pd.read_sql("select * testtable1", cnxn)
Comments
Post a Comment