这段代码给了我一个错误:
代码:
import pandas as pd
fiddy_states = pd.read_html("https://simple.wikipedia.org/wiki/List_of_U.S._states")
错误:
> ---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-9-87a39d7446f6> in <module>()
1 import pandas as pd
----> 2 df_states = pd.read_html('http://www.50states.com/abbreviations.htm#.Vmz0ZkorLIU')
C:\Anaconda3\lib\site-packages\pandas\io\html.py in read_html(io, match, flavor, header, index_col, skiprows, attrs, parse_dates, tupleize_cols, thousands, encoding)
864 _validate_header_arg(header)
865 return _parse(flavor, io, match, header, index_col, skiprows,
--> 866 parse_dates, tupleize_cols, thousands, attrs, encoding)
C:\Anaconda3\lib\site-packages\pandas\io\html.py in _parse(flavor, io, match, header, index_col, skiprows, parse_dates, tupleize_cols, thousands, attrs, encoding)
716 retained = None
717 for flav in flavor:
--> 718 parser = _parser_dispatch(flav)
719 p = parser(io, compiled_match, attrs, encoding)
720
C:\Anaconda3\lib\site-packages\pandas\io\html.py in _parser_dispatch(flavor)
661 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,lxml和BeatifulSoup4库并进行了更新。
答案 0 :(得分:1)
考虑使用xpath表达式使用lxml解析html表,然后将列表合并到数据框中:
val process: ()(implicit cache: Cache) => String = processF _ // syntax error
答案 1 :(得分:0)
尝试并使用conda来安装html5lib而不是pip。为我工作。