pandas Using pyodbc


Example

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

Specify the parameters

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

Create the connection

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

Query into pandas dataframe

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