2016-01-01 30 views
13

我試圖從維基URL中提取美國狀態,併爲此使用Python熊貓。熊貓:read_html

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

然而,上面的代碼是給我一個錯誤大號

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

我安裝html5lib和beautifulsoup4爲好,但它不工作。 有人可以幫忙請。

回答

20

在Mac

新pyvenv

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

然後跑到你的榜樣運行的Python 3.4 ....

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

所有作品......

+2

謝謝,這工作。雖然我已經安裝了所有這些程序,但我重新安裝了它,並打開了一個新實例,並且工作正常。謝謝 – user4943236

+0

很高興幫助你 –

+0

同樣的事情@TimSeed,我用pip安裝了所有東西,然後不得不重新啓動一個新的實例。 –

0

您需要使用pip安裝lxml。

pip install lxml

這對我有用。

+0

有些格式化會做魔術。更好的編輯位 – Billa