import pyodbc
import pandas as pd
import matplotlib.pyplot as plt
conn = pyodbc.connect('Driver={SQL Server};' # This is what server type we are connecting to
'Server=DESKTOP-3JKKF7H;' # This is the location and name of the server, same as what we use to connect using SSMS
'Database=AdventureWorks2019;' # This is which database we are connecting to within the selected server
'Trusted_Connection=yes;') # This allows us to forgo entering a trusted key or password because we are the admin of this computer and the...
# ... database has been configured to allow this user when we set it up.
cursor = conn.cursor()
query = 'SELECT * FROM Regional'
regional = pd.read_sql(query, conn)
print(regional.head())
regional.plot.barh(x='Region', y='Sales')
plt.xlabel("Sales (10s of millions)")
plt.show()
1条答案
按热度按时间ljo96ir51#