PYTHON

2 Easy Ways to Get Tables From a Website with Pandas

An overview of pd.read_html and pd.read_clipboard

Byron Dolon
Towards Data Science
5 min readMay 15, 2020

cartoon panda holding a computer on a green background
Image created by @siscadraws (Instagram)

The pandas library is well known for its easy-to-use data analysis capabilities. It’s equipped with advanced indexing, DataFrame joining and data aggregation features. Pandas also has a comprehensive I/O API that you can use to input data from various sources and output data to various formats.

There are many occasions when you just need to get a table from a website to use in your analysis. Here’s a look at how you can use the pandas read_html and read_clipboard to get tables from websites with just a couple lines of code.

Note, before trying any of the code below, don’t forget to import pandas.

import pandas as pd

1. pandas.read_html()

Let’s try getting this table with key Tesla executives for this example:

Yahoo Finance table of Elon Musk and other Tesla executives information

The read_html function has this description:

Read HTML tables into a list of DataFrame objects.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in Towards Data Science

Your home for data science and AI. The world’s leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.

Written by Byron Dolon

Medium has become a place to store my “how to do tech stuff” type guides. Come check out my notes on data-related shenanigans!

Responses (4)

--

--

--