【问题标题】:Impossible to load url in pandas无法在熊猫中加载网址
【发布时间】:2019-04-30 23:02:53
【问题描述】:

我最近尝试使用 pandas 加载 url 数据集 从这里:flag's dataset

我的代码是:

enter code here
Import pandas as pd
dataset= pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/flags/flag.data')
dataset.head()

一切正常,但我收到一条错误消息。我试图尽可能地理解这个消息..但我失败了。这里的消息:

TimeoutError: [WinError 10060] A connection attempt failed because the 
connected party did not properly respond after a period of time, or 
established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
<ipython-input-16-13064d485dcd> in <module>()

【问题讨论】:

  • 您是否一直收到此错误,或者重新运行代码时是否有效?我能够毫无问题地读取 URL

标签: python pandas url


【解决方案1】:

首先你应该请求获取数据,然后你可以读取它。 以下代码可能会有所帮助。

import pandas as pd
import io
import requests
url="https://archive.ics.uci.edu/ml/machine-learning-databases/flags/flag.data"
s=requests.get(url).content
c=pd.read_csv(io.StringIO(s.decode('utf-8')))

【讨论】:

    猜你喜欢
    • 2018-09-22
    • 1970-01-01
    • 2015-11-30
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    • 2018-02-27
    相关资源
    最近更新 更多