Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Python Real-World Projects

You're reading from  Python Real-World Projects

Product type Book
Published in Sep 2023
Publisher Packt
ISBN-13 9781803246765
Pages 478 pages
Edition 1st Edition
Languages
Author (1):
Steven F. Lott Steven F. Lott
Profile icon Steven F. Lott

Table of Contents (20) Chapters

Preface Chapter 1: Project Zero: A Template for Other Projects Chapter 2: Overview of the Projects Chapter 3: Project 1.1: Data Acquisition Base Application Chapter 4: Data Acquisition Features: Web APIs and Scraping Chapter 5: Data Acquisition Features: SQL Database Chapter 6: Project 2.1: Data Inspection Notebook Chapter 7: Data Inspection Features Chapter 8: Project 2.5: Schema and Metadata Chapter 9: Project 3.1: Data Cleaning Base Application Chapter 10: Data Cleaning Features Chapter 11: Project 3.7: Interim Data Persistence Chapter 12: Project 3.8: Integrated Data Acquisition Web Service Chapter 13: Project 4.1: Visual Analysis Techniques Chapter 14: Project 4.2: Creating Reports Chapter 15: Project 5.1: Modeling Base Application Chapter 16: Project 5.2: Simple Multivariate Statistics Chapter 17: Next Steps Other Books You Might Enjoy Index

Chapter 4
Data Acquisition Features: Web APIs and Scraping

Data analysis often works with data from numerous sources, including databases, web services, and files prepared by other applications. In this chapter, you will be guided through two projects to add additional data sources to the baseline application from the previous chapter. These new sources include a web service query, and scraping data from a web page.

This chapter’s projects cover the following essential skills:

  • Using the requests package for Web API integration. We’ll look at the Kaggle API, which requires signing up to create an API token.

  • Using the Beautiful Soup package to parse an HTML web page.

  • Adding features to an existing application and extending the test suite to cover these new alternative data sources.

It’s important to recognize this application has a narrow focus on data acquisition. In later chapters, we’ll validate the data and convert it to a more useful form. This reflects...

Chapter 4
Data Acquisition Features: Web APIs and Scraping

Data analysis often works with data from numerous sources, including databases, web services, and files prepared by other applications. In this chapter, you will be guided through two projects to add additional data sources to the baseline application from the previous chapter. These new sources include a web service query, and scraping data from a web page.

This chapter’s projects cover the following essential skills:

  • Using the requests package for Web API integration. We’ll look at the Kaggle API, which requires signing up to create an API token.

  • Using the Beautiful Soup package to parse an HTML web page.

  • Adding features to an existing application and extending the test suite to cover these new alternative data sources.

It’s important to recognize this application has a narrow focus on data acquisition. In later chapters, we’ll validate the data and convert it to a more useful form. This reflects...

Chapter 4
Data Acquisition Features: Web APIs and Scraping

Data analysis often works with data from numerous sources, including databases, web services, and files prepared by other applications. In this chapter, you will be guided through two projects to add additional data sources to the baseline application from the previous chapter. These new sources include a web service query, and scraping data from a web page.

This chapter’s projects cover the following essential skills:

  • Using the requests package for Web API integration. We’ll look at the Kaggle API, which requires signing up to create an API token.

  • Using the Beautiful Soup package to parse an HTML web page.

  • Adding features to an existing application and extending the test suite to cover these new alternative data sources.

It’s important to recognize this application has a narrow focus on data acquisition. In later chapters, we’ll validate the data and convert it to a more useful form. This reflects...

4.3 Summary

This chapter’s projects have shown examples of the following features of a data acquisition application:

  • Web API integration via the requests package. We’ve used the Kaggle API as an example of a RESTful API that provides data for download and analysis.

  • Parsing an HTML web page using the Beautiful Soup package.

  • Adding features to an existing application and extending the test suite to cover these new alternative data sources.

A challenging part of both of these projects is creating a suite of acceptance tests to describe the proper behavior. Pragmatically, a program without automated tests cannot be trusted. The tests are every bit as important as the code they’re exercising.

In some enterprises, the definition of done is breezy and informal. There may be a presentation or an internal memo or a whitepaper that describes the desired software. Formalizing these concepts into tangible test cases is often a significant effort. Achieving agreements can become...

4.4 Extras

Here are some ideas for you to add to these projects.

4.4.1 Locate more JSON-format data

A search of Kaggle will turn up some other interesting data sets in JSON format.

One of these is a JSON download. The other two are ZIP archives that contain JSON-format content.

This will require revising the application’s architecture to extract the JSON format data instead of CSV format data.

An interesting complication here is the distinction between CSV data and JSON data:

  • CSV data is pure text, and later conversions are required to make useful Python objects.

  • Some JSON data is converted to Python objects by the parser. Some data (like datestamps) will be left as text.

At acquisition time, this doesn’...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Python Real-World Projects
Published in: Sep 2023 Publisher: Packt ISBN-13: 9781803246765
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 $15.99/month. Cancel anytime}