简体   繁体   English

kaggle notebook 上的 sqlalchemy 库函数 create_engine().execute() 出错

[英]Error on the function create_engine().execute() from sqlalchemy library on kaggle notebook

I am trying to load data from kaggle on pandas, then, using .to_sql() function:我正在尝试从 kaggle 在熊猫上加载数据,然后使用 .to_sql() 函数:

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import sqlite3
from sqlalchemy import create_engine

df_1 = pd.read_csv("../input/bart-ridership/date-hour-soo-dest-2016.csv")
engine = create_engine('sqlite://', echo=False)
df_1.to_sql("table", con=engine)
result = engine.execute("SELECT * FROM table")

But it is throwing the next error:但它抛出了下一个错误:

    586 
    587     def do_execute(self, cursor, statement, parameters, context=None):
--> 588         cursor.execute(statement, parameters)
    589 
    590     def do_execute_no_params(self, cursor, statement, context=None):

OperationalError: (sqlite3.OperationalError) near "table": syntax error
[SQL: SELECT * FROM table]
(Background on this error at: http://sqlalche.me/e/e3q8)

TABLE is SQLite's keyword - use some other name for your table. TABLE是 SQLite 的关键字 - 为您的表使用其他名称。

Eg:例如:

df_1.to_sql("my_table", con=engine)
result = engine.execute("SELECT * FROM my_table")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM