Connecting And Basic Select

 import pyodbc

import pandas as pd 

# Some other example server values are

# server = 'localhost\sqlexpress' # for a named instance

# server = 'myserver,port' # to specify an alternate port

server = 'tcp:###r' 

database = '####' 

username = '####' 

password = '####' 

cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)

cursor = cnxn.cursor()


df = pd.read_sql_query(

    "SELECT TOP (1000) * from ####", cnxn)

df.tail(10)

Basic Graph

%matplotlib inline


df.index = df['name']

p = df.tail(10).plot.bar()



Comments