Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Data Wrangling Workshop

You're reading from   The Data Wrangling Workshop Create your own actionable insights using data from multiple raw sources

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781839215001
Length 576 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Dr. Tirthajyoti Sarkar Dr. Tirthajyoti Sarkar
Author Profile Icon Dr. Tirthajyoti Sarkar
Dr. Tirthajyoti Sarkar
Shubhadeep Roychowdhury Shubhadeep Roychowdhury
Author Profile Icon Shubhadeep Roychowdhury
Shubhadeep Roychowdhury
Brian Lipp Brian Lipp
Author Profile Icon Brian Lipp
Brian Lipp
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface
1. Introduction to Data Wrangling with Python 2. Advanced Operations on Built-In Data Structures FREE CHAPTER 3. Introduction to NumPy, Pandas, and Matplotlib 4. A Deep Dive into Data Wrangling with Python 5. Getting Comfortable with Different Kinds of Data Sources 6. Learning the Hidden Secrets of Data Wrangling 7. Advanced Web Scraping and Data Gathering 8. RDBMS and SQL 9. Applications in Business Use Cases and Conclusion of the Course Appendix

5. Getting Comfortable with Different Kinds of Data Sources

Activity 5.01: Reading Tabular Data from a Web Page and Creating DataFrames

Solution:

These are the steps to complete this activity:

  1. Import BeautifulSoup and load the data by using the following command:
    from bs4 import BeautifulSoup
    import pandas as pd
  2. Open the Wikipedia file by using the following command:
    fd = open("../datasets/List of countries by GDP (nominal) "\
              "- Wikipedia.htm", "r", encoding = "utf-8")
    soup = BeautifulSoup(fd)
    fd.close()

    Note

    Don't forget to change the path of the dataset (highlighted) based on its location on your system

  3. Calculate the tables by using the following command:
    all_tables = soup.find_all("table")
    print("Total number of tables are {} ".format(len(all_tables)))

    There are nine tables in total.

  4. Find the right table using the class attribute by using...
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 $19.99/month. Cancel anytime
Banner background image