使用 pyodbc

import pandas.io.sql
import pyodbc
import pandas as pd

指定参数

# Parameters
server = 'server_name'
db = 'database_name'
UID = 'user_id'

创建连接

# Create the connection
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=' + server + ';DATABASE=' + db + '; UID = ' + UID + '; PWD = ' + UID + 'Trusted_Connection=yes')

查询 pandas 数据帧

# Query into dataframe
df= pandas.io.sql.read_sql('sql_query_string', conn)