Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Data Science with SQL Server Quick Start Guide

You're reading from  Data Science with SQL Server Quick Start Guide

Product type Book
Published in Aug 2018
Publisher Packt
ISBN-13 9781789537123
Pages 206 pages
Edition 1st Edition
Languages
Author (1):
Dejan Sarka Dejan Sarka
Profile icon Dejan Sarka
Toc

Table of Contents (15) Chapters close

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Writing Queries with T-SQL 2. Introducing R 3. Getting Familiar with Python 4. Data Overview 5. Data Preparation 6. Intermediate Statistics and Graphs 7. Unsupervised Machine Learning 8. Supervised Machine Learning 1. Other Books You May Enjoy Index

Organizing the data


I want to start this section by showing you some of Python's analytical and graphic capabilities. I am explaining the code just briefly here; you will learn more about Python data structures very quickly. Let's start coding! First, I need to import the necessary libraries:

import numpy as np
import pandas as pd
import pyodbc
import matplotlib.pyplot as plt

For the data I will analyze, I am using the data from the AdventureWorksDW2017 demo database, selecting from the dbo.vTargetMail view, like I did in Chapter 2, Introducing R, when I introduced the R language. I am also using ODBC to connect to SQL Server, with the same data source name and SQL Server login as I did then:

con = pyodbc.connect('DSN=AWDW;UID=RUser;PWD=Pa$$w0rd')
query = """SELECT CustomerKey, 
             Age, YearlyIncome, 
             CommuteDistance, BikeBuyer
           FROM dbo.vTargetMail;"""
TM = pd.read_sql(query, con)

You can get quick info about the data with the following code, which shows the...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime