python - 尝试使用 Pandas 和 SQLAlchemy 从数据库导入时出错

标签 python sql oracle pandas 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 中的可用内容模块。你得到AttributeError如果您尝试使用 pd 中的其他内容模块,例如 pd.Series() ?

关于python - 尝试使用 Pandas 和 SQLAlchemy 从数据库导入时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28610510/

相关文章:

python - (Python) 如何使用 [ :] syntax? 对数组的每个元素使用条件语句

python - 将 numpy.float64 类型转换为 int 的 Tensorflow 问题

sql - 使用 with 子句更新语句

python - 为什么我在使用 aic_min_order 时得到 'The computed initial AR coefficients are not stationary'?

python - 如何轻松确定 Boto 3 S3 存储桶资源是否存在?

sql - 多房间预订的数据库设计 : One To Many

sql - 微软 SQL : Should ISDATE() Return "1" when Cannot Cast as Date?

asp.net - 如何从日期时间获取日期部分?

oracle - "ORA-12560: TNS:protocol adapter error"使用完整连接字符串和 EZCONNECT 绕过 tnsnames.ora 时

sql - 如何在oracle sql中查找某个日期范围内缺失的数据