pandas Read SQL Server to Dataframe Using pyodbc

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

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)


Got any pandas Question?