[Pandas] How to import from Sql Server

We need to rely on pyodbc, the sample code is as belows.

1
2
import pyodbc
cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=SQLSERVER2017;DATABASE=Adventureworks;Trusted_Connection=yes')

Write SQL and execute with pandas.read_sql

1
2
3
import pandas
query = "SELECT * from a"
df = pd.read_sql(query, sql_conn)
0%