Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Practical Business Intelligence
Practical Business Intelligence

Practical Business Intelligence: Optimize Business Intelligence for Efficient Data Analysis

eBook
£7.99 £32.99
Paperback
£41.99
Subscription
Free Trial
Renews at £16.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Practical Business Intelligence

Chapter 2. Web Scraping

The amount of data created each day on the Internet is quite staggering. Much of this data is created on social media websites as well as individual blogs. We also have data that we create from our cell phones, tablets, and wearable devices. According to the following website (http://www.livevault.com/2-5-quintillion-bytes-of-data-are-created-every-day/) in 2015 IBM reported that the average amount of data created per day is approximately 2.5 quintillion bytes. It would be useful to any organization to get their hands on this data and make sense out of it. This is where web scraping comes into play.

Simply put web scraping is a technique to extract data from different websites, manipulate the data into a structured format, and then save the data to local files for consumption and reporting. We've all probably done some form of web scraping in the past even though we may not have known it as the time.

In the previous chapter, Introduction to Practical Business Intelligence...

Getting started with R


In order for us to begin scraping websites with R, we must first get our environment set up with R, as well as RStudio. R and RStudio are available to download on many different platforms whether it be Windows, Mac, or Linux. As with everything else in this book, the environment will be set up in a Microsoft Windows 10 64-bit environment.

Downloading and installing R

R is quite easy to download and install. Any online search for CRAN (Comprehensive R Archive Network) will lead you to the latest version of R to download from the location that is closest to you. The search for R led me to the following website:  https://cran.r-project.org/bin/windows/base/.

At the time of writing this book, the latest version of R is version 3.3.2 for Windows 32/64-bit, as can be seen in the following screenshot:

Once the file has been downloaded, the next step is to begin the installation of the executable file as shown in the following screenshot:

Select the default destination where...

Web scraping with R


When we first open up RStudio, the first thing that we see is four main quadrants. These four quadrants represent our coding input as well as coding output, as shown in the following screenshot:

Let's now set up a new file, which we will use to get our web scraper up and running, by going to File | New File | R Script, as seen in the following screenshot:

We now have a blank R file to begin our coding. The next step is identifying the website data that will be the source of our web scraping exercise.

The following link (https://github.com/asherif844/PracticalBusinessIntelligence/wiki/AdventureWorks---Weekly-Data-by-Discount) within GitHub has a useful table that we can scrape from to incorporate into our database.

WeekInYear

DiscountCode

01

38

02

14

03

4

04

16

05

10

The full data in the table can also be seen in the following screenshot:

In order to scrape this Wikipedia table from R, we will need to install a couple of libraries within our R framework...

Getting started with Python


Chances are that you already have some version of Python installed on your machine, especially if you have a Mac. For the purposes of this exercise, we will be downloading Python 3 onto our Windows machine. At the time of writing this book, Python 3.5.1 is available for download; however, for the purposes of this book, we will go with the more reliable version, 3.4.4.

Downloading and installing Python

Similar to R, Python has a dedicated website for downloading appropriate versions of Python: https://www.python.org/downloads/

Once the executable file has been downloaded, run it to get the installation process started, as shown in the following screenshot:

Select the appropriate directory for the installation of Python 3.4.4. When asked to customize Python during the installation, allow all the features to be selected, especially Add python.exe to Path, as this function will allow you to just type python in a command prompt without having to type in the full path...

Web scraping with Python


Let's start a new Python notebook by going to File and selecting New Jupyter Notebook. We can assign it the following name: PercentBikeRiders by Country. We will scrape a table from the following Wikipedia website: https://github.com/asherif844/PracticalBusinessIntelligence/wiki/AdventureWorks---Detail-by-CountryCode.

This table lists country codes with the percentage of bicycle riders, as seen in the following screenshot:

In our new notebook, our first lines of code will import all of the required modules that we just finished installing, as seen in the following script:

#import packages into the project 
from bs4 import BeautifulSoup 
from urllib.request import urlopen 
import pandas as pd 

Once those have been imported, click on the play symbol button on the toolbar to execute the code inside of the cells.

At this point, you can continue to work inside of PyCharm directly, or you can copy the server IP address (http://127.0.0.1:8888) that pops...

Uploading data frames to Microsoft SQL Server


We now have two different data frames saved as comma separated value (CSV) files from GitHub and we wish to upload them to our database in Microsoft SQL Server.

Importing DiscountCodebyWeek

The two files are:

  • DiscountCodebyWeek.csv

  • CountryRegionBikes.csv

The first step is to log in to SQL Server using Management Studio and right-click on the AdventureWorks2014 database. The next step is to click on Tasks and then on Import Data.

Set your data source to be a Flat File Source and browse to select the source DiscountCodebyWeek.csv.

When choosing your data source, select the Advanced tab and rename the first column to Index, as seen in the following screenshot:

Additionally, we can rename both "WeekinYear" as well as "DiscountCode" to WeekInYear and DiscountCode by selecting each one and removing the quotes. We also want to change the data type of DiscountCode from string [DT_STR] to numeric [DT_NUMERIC] to confirm that the database will treat DiscountCode...

Summary


We have covered quite a bit in this chapter to get us started with both R and Python but our work will pay off as we move along with subsequent chapters. We went through two exercises to scrape data from GitHub using both R and Python. As can be seen, both tools have popular packages that allow for easy scraping of data. Both approaches were described in detail to allow you to find which process works better for you. Python is more generally known as a web scraping software tool; however, R has similar capabilities for similar tasks. Both approaches were presented to offer you more tools to keep in your toolbox. These are not the only packages that either programming language has to offer to allow for web scraping, but they are some of the more popular ones. Further investigation will show many other scraping packages such as scrapy for Python.

In the next chapter, we will begin our BI development with Microsoft Excel and PowerBI.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • This book will enable and empower you to break free of the shackles of spreadsheets
  • Learn to make informed decisions using the data at hand with this highly practical, comprehensive guide
  • This book includes real-world use cases that teach you how analytics can be put to work to optimize your business
  • Using a fictional transactional dataset in raw form, you’ll work your way up to ultimately creating a fully-functional warehouse and a fleshed-out BI platform

Description

Business Intelligence (BI) is at the crux of revolutionizing enterprise. Everyone wants to minimize losses and maximize profits. Thanks to Big Data and improved methodologies to analyze data, Data Analysts and Data Scientists are increasingly using data to make informed decisions. Just knowing how to analyze data is not enough, you need to start thinking how to use data as a business asset and then perform the right analysis to build an insightful BI solution. Efficient BI strives to achieve the automation of data for ease of reporting and analysis. Through this book, you will develop the ability to think along the right lines and use more than one tool to perform analysis depending on the needs of your business. We start off by preparing you for data analytics. We then move on to teach you a range of techniques to fetch important information from various databases, which can be used to optimize your business. The book aims to provide a full end-to-end solution for an environment setup that can help you make informed business decisions and deliver efficient and automated BI solutions to any company. It is a complete guide for implementing Business intelligence with the help of the most powerful tools like D3.js, R, Tableau, Qlikview and Python that are available on the market.

Who is this book for?

This book is for anyone who has wrangled with data to try to perform automated data analysis through visualizations for themselves or their customers. This highly-customized guide is for developers who know a bit about analytics but don't know how to make use of it in the field of business intelligence.

What you will learn

  • Create a BI environment that enables self-service reporting
  • Understand SQL and the aggregation of data
  • Develop a data model suitable for analytical reporting
  • Connect a data warehouse to the analytic reporting tools
  • Understand the specific benefits behind visualizations with D3.js, R, Tableau, QlikView, and Python
  • Get to know the best practices to develop various reports and applications when using BI tools
  • Explore the field of data analysis with all the data we will use for reporting

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 21, 2016
Length: 352 pages
Edition : 1st
Language : English
ISBN-13 : 9781785889974
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 21, 2016
Length: 352 pages
Edition : 1st
Language : English
ISBN-13 : 9781785889974
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
£16.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
£169.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts
£234.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total £ 117.97
Practical Machine Learning
£38.99
Principles of Data Science
£36.99
Practical Business Intelligence
£41.99
Total £ 117.97 Stars icon
Banner background image

Table of Contents

9 Chapters
Introduction to Practical Business Intelligence Chevron down icon Chevron up icon
Web Scraping Chevron down icon Chevron up icon
Analysis with Excel and Creating Interactive Maps and Charts with Power BI Chevron down icon Chevron up icon
Creating Bar Charts with D3.js Chevron down icon Chevron up icon
Forecasting with R Chevron down icon Chevron up icon
Creating Histograms and Normal Distribution Plots with Python Chevron down icon Chevron up icon
Creating a Sales Dashboard with Tableau Chevron down icon Chevron up icon
Creating an Inventory Dashboard with QlikSense Chevron down icon Chevron up icon
Data Analysis with Microsoft SQL Server Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.