The pandas read_html() function is a quick and convenient way to turn an HTML table into a pandas DataFrame. This function can be useful for quickly incorporating tables from various websites without figuring out how to scrape the site’s HTML. However, there can be some challenges in cleaning and formatting the data before analyzing it. In this article, I will discuss how to use pandas read_html()
to read and clean several Wikipedia HTML tables so that you can use them for further numeric analysis.
For the first example, we will try to parse this table from the Politics section on the Minnesota wiki page.
The basic usage is of pandas read_html
is pretty simple and works well on many Wikipedia pages since the tables are not complicated. To get started, I am including some extra imports we will use for data cleaning for more complicated examples
#html #pandas #python