Import from SQL Server into Pandas Dataframe

Python

 1|  import pandas as pd
 2|  import pyodbc as db
 3|  
 4|  #Connect to SQL Server using ODBC Driver 13 for SQL Server.
 5|  #You may need to declare a different driver depending on the server you are connecting to.
 6|  conn = db.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=ST787554;Trusted_Connection=yes;DATABASE=Orders')
 7|  
 8|  #Declare SQL Query
 9|  qry = 'SELECT * FROM SALE_ITEMS'
10|  
11|  #Run query and import data into Pandas dataframe
12|  sale_items = pd.read_sql(qry, conn)
Did you find this snippet useful?

Sign up for free to to add this to your code library