在MacBook Pro OS v10.13.2(17C88)上使用Spyder3,尝试在Python3.6中使用pandas清理表数据。代码是:
import pandas as pd
...
url = "https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130428&end="+time.strftime("%Y%m%d")
# CODE FAILS HERE
bitcoin_market_info = pd.read_html(url)[0]
控制台中显示的结果:
bitcoin_market_info = pd.read_html(url)[0]
Traceback (most recent call last):
File "<ipython-input-2-0b0d269a2c9d>", line 15, in <module>
bitcoin_market_info = pd.read_html(url)[0]
File "/Users/EL-C/anaconda3/lib/python3.6/site-packages/pandas/io/html.py", line 915, in read_html
keep_default_na=keep_default_na)
File "/Users/EL-C/anaconda3/lib/python3.6/site-packages/pandas/io/html.py", line 749, in _parse
raise_with_traceback(retained)
File "/Users/EL-C/anaconda3/lib/python3.6/site-packages/pandas/compat/__init__.py", line 385, in raise_with_traceback
raise exc.with_traceback(traceback)
TypeError: __init__() got an unexpected keyword argument 'encoding'
pd.版本为“0.21.1”
pd.show_versions()的结果:
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Darwin
OS-release: 17.3.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.21.1
pytest: 3.3.0
pip: 9.0.1
setuptools: 36.5.0.post20170921
Cython: 0.27.3
numpy: 1.13.3
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.1
openpyxl: 2.4.9
xlrd: 1.1.0
xlwt: 1.2.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
我尝试过this修复,但似乎是针对较旧的版本,而不是针对这种情况,因为我还没有导入html5lib。
如果需要:
html5lib.版本是1.0.1
bs4.版本是4.6.0
在终端中运行'pip3 install-U html5lib==“0.9999999”(如建议所示),不会更改Spyder3中的版本。
运行命令时,我在终端中看到的是:
Requirement already up-to-date: html5lib==0.9999999 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Requirement already up-to-date: six in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from html5lib==0.9999999)
也许这就是根源?如果是的话,需要帮助解决这个问题。
这是html5lib bug on github
发件人:https://stackoverflow.com/a/39087283
尝试安装Anaconda Python distributive (available for Linux, Windows and MacOS
它对我来说非常好:
模块版本:
read_html()默认使用lxml(
flavor=None
):相关问题 更多 >
编程相关推荐