Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:uuu init_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;编码';_Python_Python 3.x_Pandas - Fatal编程技术网

Python TypeError:uuu init_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;编码';

Python TypeError:uuu init_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;编码';,python,python-3.x,pandas,Python,Python 3.x,Pandas,在MacBookPro操作系统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_mar

在MacBookPro操作系统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'
我已经尝试过修复,但似乎是针对较旧的版本,而不是这种情况,因为我还没有导入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)
也许这就是根?如果是这样的话,我们需要帮助来解决这个问题

尝试安装

它对我来说非常好:

In [133]: bitcoin_market_info = pd.read_html(url)[0]

In [134]: bitcoin_market_info
Out[134]:
              Date      Open      High       Low     Close       Volume    Market Cap
0     Dec 26, 2017  14036.60  16461.20  14028.90  16099.80  13454300000  235294000000
1     Dec 25, 2017  13995.90  14593.00  13448.90  14026.60  10664700000  234590000000
2     Dec 24, 2017  14608.20  14626.00  12747.70  13925.80  11572300000  244824000000
3     Dec 23, 2017  13948.70  15603.20  13828.80  14699.20  13086000000  233748000000
4     Dec 22, 2017  15898.00  15943.40  11833.00  13831.80  22198000000  266381000000
5     Dec 21, 2017  16642.40  17567.70  15342.70  15802.90  16516600000  278827000000
6     Dec 20, 2017  17760.30  17934.70  16077.70  16624.60  22149700000  297526000000
7     Dec 19, 2017  19118.30  19177.80  17275.40  17776.70  16894500000  320242000000
8     Dec 18, 2017  19106.40  19371.00  18355.90  19114.20  14839500000  320000000000
9     Dec 17, 2017  19475.80  20089.00  18974.10  19140.80  13314600000  326141000000
...            ...       ...       ...       ...       ...          ...           ...
1694  May 07, 2013    112.25    113.44     97.70    111.50            -    1248470000
1695  May 06, 2013    115.98    124.66    106.64    112.30            -    1289470000
1696  May 05, 2013    112.90    118.80    107.14    115.91            -    1254760000
1697  May 04, 2013     98.10    115.00     92.50    112.50            -    1089890000
1698  May 03, 2013    106.25    108.13     79.10     97.75            -    1180070000
1699  May 02, 2013    116.38    125.60     92.28    105.21            -    1292190000
1700  May 01, 2013    139.00    139.89    107.72    116.99            -    1542820000
1701  Apr 30, 2013    144.00    146.93    134.05    139.00            -    1597780000
1702  Apr 29, 2013    134.44    147.49    134.00    144.54            -    1491160000
1703  Apr 28, 2013    135.30    135.98    132.10    134.21            -    1500520000

[1704 rows x 7 columns]
模块的版本:

In [135]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US
LOCALE: None.None

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: 0.7.0
xarray: 0.10.0
IPython: 6.2.1
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: 1.5.1
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.1.1
openpyxl: 2.4.9
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.1.13
pymysql: 0.7.11.None
psycopg2: 2.7.3.1 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.5.0
每个默认值使用lxml(
flavor=None
):

flavor:str或None,字符串容器

要使用的解析引擎
bs4
html5lib
是同义词,它们是

两者都有向后兼容性。默认的
None
尝试

使用
lxml
进行解析,如果解析失败,则返回到
bs4+html5lib

这是我的建议


发件人:

您能逐字发布完整的回溯吗?
url2
url
相同吗?url2与url相同。更新了问题以改变这一点,并添加了跟踪。安装了Python distributive。重新启动。没有成功。我注意到我没有安装pandas_datareader。这会有效果吗?@user,你试过用Anaconda的ipython外壳运行它吗?我认为在这种情况下,您不需要pandas_datareader…从您发布的链接通过.pkg安装distributive。代码都在Spyder3的.py文件中运行。希望能回答这个问题——我不确定你指的是在ipython shell中运行的哪个“it”。
In [135]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US
LOCALE: None.None

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: 0.7.0
xarray: 0.10.0
IPython: 6.2.1
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: 1.5.1
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.1.1
openpyxl: 2.4.9
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.1.13
pymysql: 0.7.11.None
psycopg2: 2.7.3.1 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.5.0
pip3 install -U html5lib=="0.9999999"