PYTHON
2 Easy Ways to Get Tables From a Website with Pandas
An overview of pd.read_html and pd.read_clipboard
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:
The read_html function has this description:
Read HTML tables into a
list
ofDataFrame
objects.