尝试使用 Pandas 和 SQLAlchemy 从数据库导入时出错
Error when trying to import from Database with Pandas and SQLAlchemy
我正在使用便携式 python 2.7.6.1,我想将一个查询从 oracle 数据库导入到 python pandas。我搜索了几个示例并得出了以下代码:
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()
程序在 'pd.read_sql' 语句处停止并出现此错误消息:
AttributeError: 'module' object has no attribute 'read_sql'
数据库连接正常,根据示例,此代码应该可以正常工作。有人可以帮忙吗?
pandas 模块从子模块导入 read_sql;您可以尝试从子模块中获取它:
df = pd.io.sql.read_sql('select * from databasetable', engine, index_col = index)
您还可以打印 pd.__dict__
以查看 pd
模块中可用的内容。如果您尝试使用 pd
模块中的其他内容,例如 pd.Series()
,您会得到 AttributeError
吗?
非常感谢。
我已经检查了 pd.dict 和 pandas-docs 的版本。
--> 在我的版本 0.11.0 中,似乎 'sql_read_frame'
是要使用的命令,在版本 0.15.0 中,您可以使用 'read_sql'
读取 sql
方法pandas.io.sql.read_sql
在pandas 0.12.0
中引入(发布日期:2013-07-24)。
io API changes: […] added top-level pd.read_sql and to_sql DataFrame methods
我正在使用便携式 python 2.7.6.1,我想将一个查询从 oracle 数据库导入到 python pandas。我搜索了几个示例并得出了以下代码:
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()
程序在 'pd.read_sql' 语句处停止并出现此错误消息:
AttributeError: 'module' object has no attribute 'read_sql'
数据库连接正常,根据示例,此代码应该可以正常工作。有人可以帮忙吗?
pandas 模块从子模块导入 read_sql;您可以尝试从子模块中获取它:
df = pd.io.sql.read_sql('select * from databasetable', engine, index_col = index)
您还可以打印 pd.__dict__
以查看 pd
模块中可用的内容。如果您尝试使用 pd
模块中的其他内容,例如 pd.Series()
,您会得到 AttributeError
吗?
非常感谢。
我已经检查了 pd.dict 和 pandas-docs 的版本。
--> 在我的版本 0.11.0 中,似乎 'sql_read_frame'
是要使用的命令,在版本 0.15.0 中,您可以使用 'read_sql'
方法pandas.io.sql.read_sql
在pandas 0.12.0
中引入(发布日期:2013-07-24)。
io API changes: […] added top-level pd.read_sql and to_sql DataFrame methods