In this vry brief post, I am going to show you how to create a simple Dataframe in Python using Pandas. Before proceding with this I’m using SQL server 2017 and the following sample database
http://tsql.solidq.com/SampleDatabases/TSQLV4.zip
The following code will create a DataFrame called “df”
1 2 3 4 5 6 7 8 9 10 |
import pyodbc import pandas as pd conn = pyodbc.connect('Driver={SQL Server};' 'Server=DESKTOP-DAR5KOC\SQLDEV17;' 'Database=TSQLV4;' 'Trusted_Connection=yes;') #sql_query = pd.read_sql_query('''SELECT Shipperid, Companyname, phone FROM Sales.Shippers''', conn) df = pd.read_sql_query('''SELECT Shipperid, Companyname, phone FROM Sales.Shippers''', conn) |
Next time I will talk more about how to work with the Dataframe