0% found this document useful (0 votes)
4 views7 pages

How To Read HTML Tables With Pandas (Including Example)

The document explains how to use the pandas library's read_html() function to read HTML tables into a DataFrame, including a practical example of extracting NBA team names from a Wikipedia page. It details the installation of necessary packages, the syntax for reading tables, and how to filter and rename columns in the resulting DataFrame. Additional resources for reading other file types with pandas are also provided.

Uploaded by

David Righetto
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

How To Read HTML Tables With Pandas (Including Example)

The document explains how to use the pandas library's read_html() function to read HTML tables into a DataFrame, including a practical example of extracting NBA team names from a Wikipedia page. It details the installation of necessary packages, the syntax for reading tables, and how to filter and rename columns in the resulting DataFrame. Additional resources for reading other file types with pandas are also provided.

Uploaded by

David Righetto
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

02/02/2026, 11:06 How to Read HTML Tables with Pandas (Including Example)

About Course Basic Stats Machine Learning Software Tutorials  Tools 

How to Read HTML Tables with


Pandas (Including Example)
 BY ZACH BOBBITT  LAST UPDATED ON DECEMBER 16, 2021

You can use the pandas read_html() function to


read HTML tables into a pandas DataFrame.

This function uses the following basic syntax:

df = pd.read_html('[Link]

The following example shows how to use this


function to read in a table of NBA team names
from this Wikipedia page.

Example: Read HTML Table with


Pandas

Before using the read_html() function, you’ll


likely have to install lxml:

pip install lxml

Note: If you’re using a Jupyter notebook, you


need to restart the kernel after performing this
installation.

Next, we can use the read_html() function to


read every HTML table on this Wikipedia page:

import pandas as pd
import numpy as np
import [Link] as plt
from unicodedata import normalize

[Link] 1/7
02/02/2026, 11:06 How to Read HTML Tables with Pandas (Including Example)

#read all HTML tables from specific URL


tabs = pd.read_html('[Link]

#display total number of tables read


len(tabs)

44

We can see that a total of 44 HTML tables were


found on this page.

I know that the table I’m interested in has the


word “Division” in it, so I can use the match
argument to only retrieve HTML tables that
contain this word:

#read HTML tables from specific URL with the word "D
tabs = pd.read_html('[Link]
match='Division')

#display total number of tables read


len(tabs)

I can then list the names of the columns of the


table:

#define table
df = tabs[0]

#list all column names of table


list(df)

[('Division', 'Eastern Conference'),


('Team', 'Eastern Conference'),
('Location', 'Eastern Conference'),
('Arena', 'Eastern Conference'),
('Capacity', 'Eastern Conference'),
('Coordinates', 'Eastern Conference'),
('Founded', 'Eastern Conference'),

[Link] 2/7
02/02/2026, 11:06 How to Read HTML Tables with Pandas (Including Example)
('Joined', 'Eastern Conference'),
('Unnamed: 8_level_0', 'Eastern Conference')]

I’m only interested in the first two columns, so I


can filter the DataFrame to only contain these
columns:

#filter DataFrame to only contain first two columns


df_final = [Link][:, 0:2]

#rename columns
df_final.columns = ['Division', 'Team']

#view first few rows of final DataFrame


print(df_final.head())

Division Team
0 Atlantic Boston Celtics
1 Atlantic Brooklyn Nets
2 Atlantic New York Knicks
3 Atlantic Philadelphia 76ers
4 Atlantic Toronto Raptors

The final table contains only the ‘Division’ and


‘Team’ columns.

Additional Resources

The following tutorials explain how to read other


types of files in pandas:

How to Read a Text File with Pandas


How to Read Excel Files with Pandas
How to Read CSV Files with Pandas

POSTED IN PROGRAMMING •

Zach Bobbitt
Hey there. My name is Zach Bobbitt. I
have a Masters of Science degree in
Applied Statistics and I’ve worked on

[Link] 3/7
02/02/2026, 11:06 How to Read HTML Tables with Pandas (Including Example)

machine learning algorithms for professional


businesses in both healthcare and retail. I’m
passionate about statistics, machine learning, and
data visualization and I created Statology to be a
resource for both students and teachers alike. My
goal with this site is to help you learn statistics through
using simple terms, plenty of real-world examples, and
helpful illustrations.

PREV NEXT
Pandas: How to Create and How to Perform Fisher’s Exact
Customize Plot Legends Test in SAS

Leave a Reply
Your email address will not be published.
Required fields are marked *

Comment *

Name *

Email *

POST COMMENT

[Link] 4/7
02/02/2026, 11:06 How to Read HTML Tables with Pandas (Including Example)

SEARCH

Search … 

ABOUT STATOLOGY

Statology makes learning statistics easy by


explaining topics in simple and straightforward
ways. Our team of writers have over 40 years of
experience in the fields of Machine Learning, AI
and Statistics. Learn more about our team
here.

FEATURED POSTS

Automated Exploratory Data Analysis with Sweetviz in


Python
January 30, 2026

Inside the Experiment: Testing Correlation vs.


Causation with Synthetic Data
January 29, 2026

Modeling Time-Varying Effects in Survival Analysis


January 28, 2026

How to Extract Pandas DataFrames from D-Tale


January 27, 2026

Path Analysis in Networks: Understanding


Connectivity with Python
January 27, 2026

How to Load Pandas DataFrames into D-Tale


January 26, 2026

STATOLOGY STUDY

[Link] 5/7
02/02/2026, 11:06 How to Read HTML Tables with Pandas (Including Example)

Statology Study is the ultimate online statistics study guide that helps
you study and practice all of the core concepts taught in any elementary
statistics course and makes your life so much easier as a student.

INTRODUCTION TO STATISTICS COURSE

Introduction to Statistics is our premier online video course that


teaches you all of the topics covered in introductory statistics. Get
started with our course today.

YOU MIGHT ALSO LIKE

How to Read CSV File from String into Pandas


DataFrame

The Ultimate Guide: How to Read Excel Files


with Pandas

Pandas: How to Only Read Specific Rows from


CSV File

The Ultimate Guide: How to Read CSV Files with


Pandas

Pandas: Set Column Names when Importing


Excel File

Pandas: How to Read Excel File with Merged


Cells

[Link] 6/7
02/02/2026, 11:06 How to Read HTML Tables with Pandas (Including Example)

© 2025 Statology | Privacy Policy | Terms of Use

[Link] 7/7

You might also like