[英]Pandas: read_html
我正在嘗試從維基URL中提取美國各州,並且我正在使用Python Pandas。
import pandas as pd
import html5lib
f_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
但是,上面的代碼給了我一個錯誤L.
(1)導入pandas中的ImportError Traceback(最近調用最后一次)為pd ----> 2 f_states = pd.read_html(' https://simple.wikipedia.org/wiki/List_of_U.S._states ')
如果在('bs4','html5lib')中有味道:662如果不是_HAS_HTML5LIB: - > 663引發ImportError(“找不到html5lib,請安裝它”)664如果不是_HAS_BS4:665引發ImportError(“BeautifulSoup4(bs4)not not發現,請安裝它“)ImportError:找不到html5lib,請安裝它
我也安裝了html5lib和beautifulsoup4,但它無法正常工作。 有人可以幫忙嗎?
在mac上運行Python 3.4
新的pyvenv
pip install pandas
pip install lxml
pip install html5lib
pip install BeautifulSoup4
然后運行你的例子它應該工作:
import pandas as pd
import html5lib
f_states= pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
另請考慮在https://www.continuum.io/downloads上安裝所需的軟件包。 而不是pip安裝,你會conda安裝你的包。
$ conda install html5lib
你需要使用pip安裝lxml。
pip install lxml
這對我有用。
為此你只需要安裝
pip install pandas
pip install lxml
然后你必須導入它們並運行你的程序
import pandas as pd
f_states=pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
如果你的環境是Anaconda Jupiter筆記本。
你需要另一套安裝評論:
conda install lxml
conda install html5lib
conda install BeautifulSoup4
然后在Jupiter筆記本中運行python代碼。
import pandas as pd
f_states= pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.