熊猫:read_html

新手上路,请多包涵

我正在尝试从 wiki 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 import pandas as pd —-> 2 f_states = pd.read_html(’ https://simple.wikipedia.org/wiki/List_of_U.S._states ‘) 中的 ImportError Traceback (most recent call last)

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找到,请安装”) ImportError: html5lib not found,请安装

我也安装了 html5lib 和 beautifulsoup4,但它不工作。有人可以帮忙吗?

原文由 user4943236 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 800
2 个回答

在 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')

原文由 Tim Seed 发布,翻译遵循 CC BY-SA 4.0 许可协议

还可以考虑 conda 在 https://www.continuum.io/downloads 安装你需要的包。您可以使用 conda 安装您的软件包,而不是 pip 安装。

 $ conda install html5lib

原文由 user6015032 发布,翻译遵循 CC BY-SA 3.0 许可协议

推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏