I'm working with some data in Azure ML, using Jupyter notebooks.
I've gathered the data from an Azure SQL database by setting the tables up as assets and then used Python to run some machine learning models and ouptut a simple pandas data frame of results.
I now need to write that results data frame back to the Azure SQL database.
I have the following code, but I don't know what to put for the driver - if someone can help, that would be great - otherwise, is there a better way of doing this?
import sqlalchemy
import pyodbc
data = [
['94732','John', 'Y', 'Seg1'],
['93045','Jane', 'N', 'Seg2']]
headers=['ID', 'name', 'Class', 'Segment']
testing_df = pd.DataFrame(data, columns=headers)
testing_df
server = 'server.windows.net '
database = 'database'
username = 'username'
password = 'pwd'
driver= '{ODBC Driver 17 for SQL Server}'
conn_str = f'DRIVER={driver};SERVER={server};DATABASE={database};UID={username};PWD={password}'
conn = pyodbc.connect(conn_str)
table_name = 'ddo_datacove_output_test'
testing_df.to_sql(table_name, conn, index=False, if_exists='append')
Use the
ODBCdriver which is present in local machine and Jupyter notebook. If the driver version is17then you need to check whether it is present in local machine or not. To get driver versions check this document and install requiredODBCaccordingly.Below code uses
ODBCversion18which is present in my local machine and as well as in jupyter notebook. To check the version ofODBCin jupyter use this commandpyodbc.drivers()Output: