【发布时间】:2018-06-08 12:35:12
【问题描述】:
尝试在 MacBook Pro OS v10.13.2 (17C88) 上使用 Spyder3 在 Python 3.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)
也许这是根?如果是这样,需要帮助解决这个问题。
【问题讨论】:
标签: python python-3.x pandas