【问题标题】:jupyter notebook seaborn load_dataset https error: 404 not foundjupyter notebook seaborn load_dataset https错误:找不到404
【发布时间】:2020-09-26 06:55:00
【问题描述】:

您好,我是一名学生,希望使用 jupyter notebook 来表示学校任务的数据集。

import seaborn as sns
spotify = sns.load_dataset('top10s.csv')

这是我在网上找到的一个数据集,当我尝试运行此代码时,我得到了 HTTPError

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-2-af1fc80c3c1b> in <module>
      1 import seaborn as sns
----> 2 spotify = sns.load_dataset('top10s.csv')

~\Anaconda3\lib\site-packages\seaborn\utils.py in load_dataset(name, cache, data_home, **kws)
    426                                   os.path.basename(full_path))
    427         if not os.path.exists(cache_path):
--> 428             urlretrieve(full_path, cache_path)
    429         full_path = cache_path
    430 

~\Anaconda3\lib\urllib\request.py in urlretrieve(url, filename, reporthook, data)
    245     url_type, path = splittype(url)
    246 
--> 247     with contextlib.closing(urlopen(url, data)) as fp:
    248         headers = fp.info()
    249 

~\Anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    220     else:
    221         opener = _opener
--> 222     return opener.open(url, data, timeout)
    223 
    224 def install_opener(opener):

~\Anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
    529         for processor in self.process_response.get(protocol, []):
    530             meth = getattr(processor, meth_name)
--> 531             response = meth(req, response)
    532 
    533         return response

~\Anaconda3\lib\urllib\request.py in http_response(self, request, response)
    639         if not (200 <= code < 300):
    640             response = self.parent.error(
--> 641                 'http', request, response, code, msg, hdrs)
    642 
    643         return response

~\Anaconda3\lib\urllib\request.py in error(self, proto, *args)
    567         if http_err:
    568             args = (dict, 'default', 'http_error_default') + orig_args
--> 569             return self._call_chain(*args)
    570 
    571 # XXX probably also want an abstract factory that knows when it makes

~\Anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
    501         for handler in handlers:
    502             func = getattr(handler, meth_name)
--> 503             result = func(*args)
    504             if result is not None:
    505                 return result

~\Anaconda3\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)
    647 class HTTPDefaultErrorHandler(BaseHandler):
    648     def http_error_default(self, req, fp, code, msg, hdrs):
--> 649         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    650 
    651 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 404: Not Found

我不知道如何解决这个问题 或者为什么我什至得到问题

我希望有人可以帮助我 并感谢您的宝贵时间

【问题讨论】:

    标签: jupyter-notebook dataset seaborn jupyter http-error


    【解决方案1】:

    sns.load_dataset() 从在线搜索数据集。它不会从您的工作目录导入数据集。

    这里是 seaborn load_dataset 函数的documentation

    假设您的数据集 top10s.csv 与您的 python 文件位于同一文件夹中,您应该使用 pandas 代替。

    import pandas as pd
    
    spotify = pd.read_csv('top10s.csv')
    

    请注意,您必须在通过 pip 导入之前安装此库,如下所示:

    pip install pandas
    

    【讨论】:

      【解决方案2】:

      您需要安装最新的 zipline 主分支。你可以这样做:

      pip install zipline
      

      【讨论】:

        【解决方案3】:

        代码中有2个错误。

        1. 我们可以使用 sns.load_dataset 仅加载 seaborn 网站中存在的数据集,因为它用于https://github.com/mwaskom/seaborn-data 上的在线 CSV 文件。

        2. 在指定数据集名称时,无需指定数据集的扩展名。下面是加载tips数据集的示例代码。

          import seaborn as sns
          
          tips = sns.load_dataset("tips")
          tips.head()
          

        【讨论】:

          猜你喜欢
          • 2015-07-31
          • 2016-08-16
          • 2018-04-26
          • 1970-01-01
          • 1970-01-01
          • 2019-08-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多