【发布时间】:2021-04-29 06:17:33
【问题描述】:
我正在尝试在 jupyter notebook 中进行查询并将其保存在 pandas 数据框中。
这是我写的代码:
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=DESKTOP-P2RVLB2\RENO_DATACAMP;'
'Database=Introduction_to_SQL_Server;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
# SELECT the country column FROM the eurovision table
sql_query = pd.read_sql_query('SELECT description, event_year from Introduction_to_SQL_Server.dbo.grid WHERE description ='Vandalism';',conn)
print(sql_query)
print(type(sql_query))
并显示如下错误:
File "<ipython-input-69-0c8fd6cbc2be>", line 9
sql_query = pd.read_sql_query('SELECT description, event_year from Introduction_to_SQL_Server.dbo.grid WHERE description ='Vandalism';',conn)
^
SyntaxError: invalid syntax
请帮我解决这个错误,提前谢谢!
【问题讨论】:
标签: python sql-server pandas dataframe jupyter-notebook