pd.read_html() imports a list rather than a dataframe
<p>I used <code>pd.read_html()</code> to import a table from a webpage but instead of structuring the data as a dataframe Python imported it as a list.  How can I import the data as a dataframe?  Thank you!</p>

<p>The code is the following:</p>

<pre><code>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
</code></pre>

<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_html.html" rel="nofollow"><code>.read_html()</code></a> produces a <em>list of dataframes</em> (there could be multiple tables in an HTML source), get the desired one by index. In your case, there is a single dataframe:</p>

<pre><code>dfs = pd.read_html(url)
df = dfs[0]
print(df)
</code></pre>

<p>Note that, if there are no <code>table</code>s in the HTML source, it would return an error and would never produce an empty list.</p>

python html pandas