python - Pandas :read_html

标签 python pandas

我正在尝试从 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

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,但它不起作用。 有人可以帮忙吗?

最佳答案

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

关于python - Pandas :read_html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34555135/

相关文章:

Python Pandas - 在列中搜索值并附加到新列

python - 如何从具有 HHMM、HMM、MM 和 M 格式的整数值的 pandas 列中有效提取小时和分钟?

python - Flask - 获取 html 选择选项标签内的文本而不是选项的值

python - 混合定义如何在枚举中工作?

python - 确保两个 Pandas DatetimeIndex 相同?

python - python dict 和 PyQt 小部件之间连接的最佳方式是什么?

python - 自动拆分并生成列

python - 使用 Python 提取数据

python - 按小时将日期时间对象排序为 Pandas 数据框,然后使用 Matplotlib 可视化为直方图

amazon-ec2 - 如何通过 SSH 在 EC2 实例上安装 Pandas