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

2024-10-01 09:39:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是PortablePython2.7.6.1,我想从oracle数据库导入一个查询到PythonPandaps。我搜索了几个示例,得出了以下代码:

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语句'-带有此错误消息的语句:

^{pr2}$

数据库连接正在工作,根据示例,此代码应该可以工作。有人能帮忙吗?在


Tags: 代码fromimport数据库示例dfreadsql
3条回答

方法^{}在{}中引入(发布日期:2013-07-24)。在

{a2}

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

pandas模块从子模块导入read_sql;您可以尝试从子模块获取它:

df = pd.io.sql.read_sql('select * from databasetable', engine, index_col = index)

您还可以打印pd.__dict__以查看pd模块中提供了哪些内容。如果您尝试使用pd模块中的其他内容,例如pd.Series(),您是否会得到AttributeError?在

非常感谢。 我已经和警察局核实过了。dict和pandas文档上的版本。 >;在我的版本0.11.0中,'sql_read_frame'似乎是要使用的命令,在版本0.15.0中,您可以使用'read_sql'读取sql

相关问题 更多 >