Reputation: 1493
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?
Upvotes: 5
Views: 7607
Reputation: 83177
The method pandas.io.sql.read_sql
was introduced in pandas 0.12.0
(Release date: 2013-07-24).
io API changes: […] added top-level pd.read_sql and to_sql DataFrame methods
Upvotes: 0
Reputation: 1493
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'
Upvotes: 0
Reputation: 5468
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()
?
Upvotes: 2