Assuming you have imported pandas
and parsed an HTML file with BeautifulSoup into an object called soup
, you can convert the contents of a table into a pandas dataframe using the following code:
main.py81 chars5 lines
In this code, we first find the table
tag in the HTML using the find()
method of BeautifulSoup. Then str(table)
is passed as an argument to the pandas read_html()
function to parse the HTML and convert it to a dataframe. The [0]
indexer is used to select the first (and hopefully only) table found in the HTML.
gistlibby LogSnag