【发布时间】:2021-09-01 12:16:59
【问题描述】:
我正在创建必要的连接,然后创建要发送到 Azure SQL 数据库的数据框。 我在最后一部分卡住了。 任何帮助将不胜感激。
#The last line of code gives me the programming error as stated in the question
#Please, please try to help me with this , I will be eternally grateful
#Creating connections
import pandas as pd
from sqlalchemy import create_engine, MetaData, Table, select
from six.moves import urllib
params = urllib.parse.quote_plus(r'Driver={ODBC Driver 17 for SQL
Server};Server=tcp:abcd.sql.azuresynapse.net,1433;Database=xxx;Uid=yyy;Pwd=
{zzz};Encrypt=yes;TrustServerCertificate=yes;Connection Timeout=30;')
conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params)
engine = create_engine(conn_str,connect_args={'autocommit': True})
engine.connect()
#Create dataframe
df=pd.DataFrame(columns=['Name','Subject','Marks','GPA'])
df['Name']=['A','B','C','D','E']
df['Subject']=['IUDI','KDBJSCJ','SJIJSABCIBSA','DCOSANNOA','SDOISD']
df['Marks']=[659 for i in range(0,5)]
df['GPA']=[8.0 for i in range(0,5)]
#Export Dataframe to sql (Problem code)
df.to_sql(name='demo_table',con=engine,index=False)
【问题讨论】:
-
嗨@bkghosh,如果我在答案中理解错误,请纠正我。 :)
标签: python azure azure-synapse