我最近尝试使用熊猫加载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>()
答案 0 :(得分:0)
首先,您应该请求获取数据,然后才能读取它。 以下代码可能会有所帮助。
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')))