Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Learn Python by Building Data Science Applications
Learn Python by Building Data Science Applications

Learn Python by Building Data Science Applications: A fun, project-based guide to learning Python 3 while building real-world apps

eBook
$17.99 $26.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Learn Python by Building Data Science Applications

Preparing the Workspace

Welcome! We're very excited to start learning and building things with you! However, we need to get ourselves ready first.

In this chapter, we'll learn how to download and install everything you'll need throughout the book, including Python itself, all the Python packages that we'll need, and two development tools we will be using extensively: Jupyter and Visual Studio Code (VS Code). After that, we'll go through a brief overview of Jupyter and VS Code interfaces. Finally, you will run your very first line of Python, so we need to ensure that everything is ready before we dive in.

In this chapter, we'll cover the following:

  • The minimum computer configuration required
  • How to install the Anaconda distribution
  • How to download the code for this book
  • Setting up and getting familiar with VS Code and Jupyter
  • Running your first line...

Technical requirements

Python can be very humble and does not require an advanced computer. In fact, you can run Python on a $10 Raspberry Pi or an Arduino board! The code and data we use in this book do not require any special computational power, any laptop, or any computer made after 2008. At least 2 GB of RAM, 20 GB of disk space, and an internet connection should suffice. Your operating system (OS) shouldn't be a problem either, as Python and all the tools we will use are cross-platform and work on Windows, macOS, and Linux.

Throughout the book, we'll use two main tools to write the code: Jupyter and VS Code. Both of them are free and aren't demanding.

All the code for the book is publicly available and free to access at https://github.com/PacktPublishing/Learn-Python-by-Building-Data-Science-Applications.

Installing Python

There are multiple Python distributions, starting with the original, vanilla Python, which is accessible at https://www.python.org/. Data analysis, however, adds unique requirements for packaging (https://www.youtube.com/watch?v=QjXJLVINsSA&feature=youtu.be&t=3555). In this book, we use Anaconda, which is an open source and free Python distribution, designed for data science and machine learning. Anaconda's main features include a smooth installation of data science packages (many of which run C and Fortran languages under the hood) and conda, which is a great package and environment manager (we will talk more about environments and conda later in Chapter 9, Shell, Git, Conda, and More – at Your Command). Conveniently, the Anaconda distribution installs all the packages (https://docs.anaconda.com/anaconda/packages/pkg-docs/) we need in this...

Downloading materials for running the code

All code in this book is also available as a separate archive of files—either Python scripts or Jupyter notebooks. You can download the full archive and follow along with the book using the relevant code from GitHub (https://github.com/PacktPublishing/Learn-Python-by-Building-Data-Science-Applications). Everything is stored on GitHub, which is an online service for code storage with version control. We will discuss both Git and GitHub in Chapter 9, Shell, Git, Conda, and More – at Your Command, but in this case, you won't need version control, so it is easier to download everything as an archive. Just use the Clone or download button on the right side (1), and select Download ZIP (2):

Once the download is complete, unzip the file and move it to a convenient location. This folder will be our main workspace throughout...

Working with VS Code

VS Code is invaluable for Python development and experimentation. VS Code—not to be confused with Visual Studio, which is a commercial product—is a sophisticated, completely free, and open source text editor created by Microsoft. It is language-agnostic and will work perfectly with Python, JavaScript, Java, or any other language. VS Code has hundreds of built-in features and thousands of great plugins to expand its capabilities.

In order to install VS Code, head to its main web page, https://code.visualstudio.com/, and download the package for your OS. The installation is pretty straightforward; there is no need to change any of the default settings. Assuming you installed VS Code as part of the previous steps, you now need to open the VS Code application. Next, switch to the plugin marketplace menu (as shown in the following screenshot), type...

Beginning with Jupyter

Another development environment we'll use is Jupyter. If you have installed Anaconda, then Jupyter is already on your machine, as it is one of the tools that come with Anaconda. To start using Jupyter, we need to run it from the Terminal (you might need to open a new Terminal to update the paths). The following code will run a newer version of the tool's frontend face, and that is what we'll use:

$ jupyter lab

Alternatively, it also supports an older version of the frontend via Jupyter Notebook. The two have their differences, but we'll stick with the lab.

The app's behavior depends on the folder from which it was started; it is more convenient to run it directly from the project's root folder. That's why it is so handy that VS Code's Terminal opens in a workspace folder by itself, as we don't need to navigate...

Pre-flight check

Before we proceed to the content of this book, let's ensure our code can actually be executed by running the simplest possible code in Jupyter. To do this, let's create a test notebook and run some code to ensure everything works as intended. Click on the Python 3 square in the Notebook section. A new tab should open, called Untitled.ipynb.

First, the blue line highlighted represents the selected cell in the notebook. Each cell represents a separate snippet of code, which is executed simultaneously in one step. Let's write our very first line of code in this cell:

print('Hello world')

Now, hit Shift + Enter. This shortcut executes the selected cells in Python and outputs the result on the next line. It also automatically creates a new input cell if there are none, as shown in the following screenshot. The number on the left gives a hint...

Summary

In this chapter, we prepared our working environment for the journey ahead. In particular, we installed the Anaconda Scientific Python Distribution with Python 3.7.2, which includes all the packages we'll need throughout the course of this book. We also installed and learned about the basics of VS Code, which is a sophisticated and interactive development environment that will be our primary tool for writing arbitrary code, and Jupyter, which we use for experimentation and analysis. Finally, we discussed and even ran some code already! We did this in Jupyter, which is a coding environment that is perfect for prototyping, experimentation, analysis, and educational purposes.

In the next chapter, we'll begin our introduction to Python, learning about variables, variable assignment, and Python's basic data types.

...

Questions

  1. What version of Python do we use?
  2. Will it work on a Windows PC?
  3. Do I need to install any additional packages?
  4. What is a Jupyter Notebook?
  5. When and why should I use Jupyter Notebooks?
  6. When should I switch to VS Code?
  7. Can I run the code from this book on my smartphone/tablet?
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn the basics of developing applications with Python and deploy your first data application
  • Take your first steps in Python programming by understanding and using data structures, variables, and loops
  • Delve into Jupyter, NumPy, Pandas, SciPy, and sklearn to explore the data science ecosystem in Python

Description

Python is the most widely used programming language for building data science applications. Complete with step-by-step instructions, this book contains easy-to-follow tutorials to help you learn Python and develop real-world data science projects. The “secret sauce” of the book is its curated list of topics and solutions, put together using a range of real-world projects, covering initial data collection, data analysis, and production. This Python book starts by taking you through the basics of programming, right from variables and data types to classes and functions. You’ll learn how to write idiomatic code and test and debug it, and discover how you can create packages or use the range of built-in ones. You’ll also be introduced to the extensive ecosystem of Python data science packages, including NumPy, Pandas, scikit-learn, Altair, and Datashader. Furthermore, you’ll be able to perform data analysis, train models, and interpret and communicate the results. Finally, you’ll get to grips with structuring and scheduling scripts using Luigi and sharing your machine learning models with the world as a microservice. By the end of the book, you’ll have learned not only how to implement Python in data science projects, but also how to maintain and design them to meet high programming standards.

Who is this book for?

If you want to learn Python or data science in a fun and engaging way, this book is for you. You’ll also find this book useful if you’re a high school student, researcher, analyst, or anyone with little or no coding experience with an interest in the subject and courage to learn, fail, and learn from failing. A basic understanding of how computers work will be useful.

What you will learn

  • Code in Python using Jupyter and VS Code
  • Explore the basics of coding – loops, variables, functions, and classes
  • Deploy continuous integration with Git, Bash, and DVC
  • Get to grips with Pandas, NumPy, and scikit-learn
  • Perform data visualization with Matplotlib, Altair, and Datashader
  • Create a package out of your code using poetry and test it with PyTest
  • Make your machine learning model accessible to anyone with the web API

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 30, 2019
Length: 482 pages
Edition : 1st
Language : English
ISBN-13 : 9781789535365
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Aug 30, 2019
Length: 482 pages
Edition : 1st
Language : English
ISBN-13 : 9781789535365
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 132.97
Python Programming Blueprints
$54.99
Learn Programming in Python with Cody Jackson
$38.99
Learn Python by Building Data Science Applications
$38.99
Total $ 132.97 Stars icon

Table of Contents

25 Chapters
Section 1: Getting Started with Python Chevron down icon Chevron up icon
Preparing the Workspace Chevron down icon Chevron up icon
First Steps in Coding - Variables and Data Types Chevron down icon Chevron up icon
Functions Chevron down icon Chevron up icon
Data Structures Chevron down icon Chevron up icon
Loops and Other Compound Statements Chevron down icon Chevron up icon
First Script – Geocoding with Web APIs Chevron down icon Chevron up icon
Scraping Data from the Web with Beautiful Soup 4 Chevron down icon Chevron up icon
Simulation with Classes and Inheritance Chevron down icon Chevron up icon
Shell, Git, Conda, and More – at Your Command Chevron down icon Chevron up icon
Section 2: Hands-On with Data Chevron down icon Chevron up icon
Python for Data Applications Chevron down icon Chevron up icon
Data Cleaning and Manipulation Chevron down icon Chevron up icon
Data Exploration and Visualization Chevron down icon Chevron up icon
Training a Machine Learning Model Chevron down icon Chevron up icon
Improving Your Model – Pipelines and Experiments Chevron down icon Chevron up icon
Section 3: Moving to Production Chevron down icon Chevron up icon
Packaging and Testing with Poetry and PyTest Chevron down icon Chevron up icon
Data Pipelines with Luigi Chevron down icon Chevron up icon
Let's Build a Dashboard Chevron down icon Chevron up icon
Serving Models with a RESTful API Chevron down icon Chevron up icon
Serverless API Using Chalice Chevron down icon Chevron up icon
Best Practices and Python Performance Chevron down icon Chevron up icon
Assessments Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.8
(4 Ratings)
5 star 25%
4 star 0%
3 star 0%
2 star 75%
1 star 0%
Hoi Nguyen Aug 17, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book with smart coding included!
Amazon Verified review Amazon
George Paquin Jun 14, 2024
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
So far, I've not been able to get Anaconda to install on linux mint. So my experience is. "What a pain". Might be a decent product, but so far it's disappointing. I think I'm going to have to set up a new system just to run it. Or find a linux mentor.
Feefo Verified review Feefo
Tony Apr 25, 2022
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I am three quarters finished woth the book and there are many hurdles for a beginner of python. Number one the book uses an extremely complicated database about world war 2 battles. The database should have been less complicated since the book is supposedly meant for beginners of python. This complicated database is used again and again throughout the book for various tasks which impedes the learning process. Why couldn't the author have chosen a simpler database? The book starts out showing elements of the python language. At times the lessons are not bad. But then the author goes into this confusing complicated datascraping example which he uses for the next half of the book thereby confusing the reader. Why wasn't the datascraping explained to a beginner audience?? The section on data cleaning is super complicated using regex and was not explained well at all. I have about one quarter of the book left and I will update my review if i notice any improvement. The bottom line is that the author does not explain concepts to a beginner python audience like the book claims. He throws around terms like the reader is familiar with them like " pipes" without adequately explaining them. I am familiar with C and Java and I was still confused with the author's explanations. The bottom line: This is just NOT a book for python beginners and the explanations of real complicated concepts are lacking at best and down right confusing at worst.UPDATE: I continued to read the book and I just about gave up. From chapter 13 to the end gets progessively complicated and so disappointing, I had high hopes for this book to teach me python and data science at the same time, while it barely teaches either one. The problem here is that the author just does NOT explain every line of code. ANd the lines of code which he bothers to explain are not explained adequately. He just throws SUPER complicated code at you and expects you to understand it. On page 5 he states: " The book is designed for complete beginners..." Really?? If you are a beginner wouldn't you want every line of code explained? Or would you like the author to throw code at you and ASSUME you understand it? I wish this book would have been like the book: Artificial Intelligence and Deep Learning with Python: Every Line of Code Explained For Readers New to AI and New to Python. In that book each and every line of python code IS explained , profusely. I am extremely dissapointed.
Amazon Verified review Amazon
Ricardo Cavallí Feb 11, 2020
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Quite a bit of the code does not work and the author doesn't respond to social media for help...I would return it if it wasn't digital.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.