Markus W Markus W - 1 year ago 100
SQL Question

Error when trying to import from Database with Pandas and SQLAlchemy

I am using portable python and I want to import a query from an oracle database into python pandas. I have searched a couple of examples and came up with the following code:

from sqlalchemy import create_engine
import pandas as pd

engine = create_engine('oracle://user:pass@host:port/schema', echo=False)
df = pd.read_sql('select * from databasetable', engine, index_col = index)

print df.describe()

The program stops at the 'pd.read_sql'-statement with this Error Message:

AttributeError: 'module' object has no attribute 'read_sql'

The Database connection is working and according to the examples this code should work. Can anyone help?

Answer Source

The pandas module imports read_sql from a submodule; you could try getting it from the submodule:

df ='select * from databasetable', engine, index_col = index)

You could also print pd.__dict__ to see what's available in the pd module. Do you get AttributeError if you try to use other things from the pd module, for example, pd.Series()?