SNIPPET
2 Upvotes

Import from SQL Server into Pandas Dataframe

Python
Import and Export

import pandas as pd
import pyodbc as db

#Connect to SQL Server using ODBC Driver 13 for SQL Server.
#You may need to declare a different driver depending on the server you are connecting to.
conn = db.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=ST787554;Trusted_Connection=yes;DATABASE=Orders')

#Declare SQL Query
qry = 'SELECT * FROM SALE_ITEMS'

#Run query and import data into Pandas dataframe
sale_items = pd.read_sql(qry, conn)

By analyseup - Last Updated Nov. 24, 2020, 4:03 p.m.

COMMENTS
RELATED SNIPPETS
Search Snippets by Tag: