简体   繁体   中英

Pandas: read_html

I'm trying to extract US states from wiki URL, and for which I'm using Python Pandas.

import pandas as pd
import html5lib
f_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states') 

However, the above code is giving me an error L

ImportError Traceback (most recent call last) in () 1 import pandas as pd ----> 2 f_states = pd.read_html(' https://simple.wikipedia.org/wiki/List_of_U.S._states ')

if flavor in ('bs4', 'html5lib'): 662 if not _HAS_HTML5LIB: --> 663 raise ImportError("html5lib not found, please install it") 664 if not _HAS_BS4: 665 raise ImportError("BeautifulSoup4 (bs4) not found, please install it") ImportError: html5lib not found, please install it

I installed html5lib and beautifulsoup4 as well, but it is not working. Can someone help pls.

Running Python 3.4 on a mac

New pyvenv

pip install pandas
pip install lxml
pip install html5lib
pip install BeautifulSoup4

Then run your example and it should work:

import pandas as pd
import html5lib
f_states=   pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states') 

Also consider conda installing your required packages at https://www.continuum.io/downloads . Instead of pip installing, you would conda install your packages.

$ conda install html5lib 

You need to install lxml using pip.

pip install lxml

this worked for me.

For that you just need to install

pip install pandas
pip install lxml

and then you have to import those and run your program

import pandas as pd
f_states=pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states') 

if your environment is Anaconda Jupiter notebook.

you need another set of install comment:

conda install lxml
conda install html5lib
conda install BeautifulSoup4

then run the python code in Jupiter notebook.

import pandas as pd
f_states=   pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states') 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM