5

I am using portable python 2.7.6.1 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?

2
  • Is your code correct, you have double single quotes in your param to create_engine also for your sql statement, does it work if you pass a raw string: df = pd.read_sql(r'select * from databasetable', engine, index_col = index) Commented Feb 19, 2015 at 15:53
  • the 'create engine' works without errors. I have tried the raw string and I am getting the same error. It feels as if the 'read_sql' is not found in pandas. But this seems odd to me. Commented Feb 19, 2015 at 16:02

3 Answers 3

2

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

df = pd.io.sql.read_sql('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()?

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

1 Comment

Thanks a lot. I have checked with pd.__dict__ and the on the pandas-docs for the versions. --> It seems in my version 0.11.0 'sql_read_frame' is the command to use and in Version 0.15.0 you can read sql with 'read_sql'.
0

Thanks a lot. I have checked with pd.dict and the on the pandas-docs for the versions. --> It seems in my version 0.11.0 'sql_read_frame' is the command to use and in Version 0.15.0 you can read sql with 'read_sql'

Comments

0

The method pandas.io.sql.read_sql was introduced in pandas 0.12.0 (Release date: 2013-07-24).

Change log:

io API changes: […] added top-level pd.read_sql and to_sql DataFrame methods

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.