Pd.read_html () imports a list, not a data block

I used pd.read_html() to import a table from a web page, but instead of structuring the data as a data frame, Python imported it as a list. How to import data as a data frame? Thanks!

The code is as follows:

 import pandas as pd import html5lib url = 'http://www.fdic.gov/bank/individual/failed/banklist.html' dfs = pd.read_html(url) type(dfs) Out[1]: list 
+8
source share
2 answers

.read_html() creates a list of .read_html() in the HTML source, there can be several tables), getting the desired index. In your case, there is one data frame:

 dfs = pd.read_html(url) df = dfs[0] print(df) 

Note that if there is no table in the HTML source, it will throw an error and will never produce an empty list.

+5
source
 import pandas as pd import html5lib url = 'http://www.fdic.gov/bank/individual/failed/banklist.html' dfs = pd.read_html(url) df = pd.concat(dfs) df 
0
source

All Articles