Pandas.io.sql返回该表不存在,即使它存在

2024-09-29 01:26:20 发布

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

这是我的代码,我在WindowsXP上运行,在ipython笔记本里。在

import os
os.getcwd() # This is current working directory 

db_path = '..\\06_django\\hzmo_web\\hzmo_web\\hzmo_backup_05_2013.db'


import sqlite3
from pandas.io import sql
# Create your connection.
cnx = sqlite3.connect('db_path')

cnx

cur = cnx.cursor()    
cur.execute('SELECT SQLITE_VERSION()')
data = cur.fetchone()
print "SQLite version: %s" % data 

import contextlib
with contextlib.closing(sqlite3.connect(db_path)) as conn:
    conn.row_factory = sqlite3.Row
    cursor = conn.cursor()    
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
    for tablerow in cursor.fetchall():
        print tablerow[0]
        #table = tablerow[0]
        #cursor.execute("SELECT * FROM {t}".format(t = table))
        #for row in cursor:
        #    for field in row.keys():
        #        print(table, field, row[field])

sql.read_frame('SELECT * FROM hzmo_report;', cnx)

我只想从pandas DataFrame中的hzmo_报告表中选择所有数据,正如我在http://pandas.pydata.org/pandas-docs/stable/io.html#sql-queries的文档中看到的那样

我得到的错误是:操作错误:没有这样的表:hzmo_报告 但那张桌子确实存在。在

^{pr2}$

有人知道问题出在哪里吗?在


Tags: pathimportpandasexecutedbsqltableselect
1条回答
网友
1楼 · 发布于 2024-09-29 01:26:20
cnx = sqlite3.connect('db_path')

这个参数不应该是您创建的变量,而不是字符串吗?在上述情况下,您可能正在连接一个名为“db_path”的新数据库。在

^{pr2}$

相关问题 更多 >