【问题标题】:File not found error in Jupyter lab using python使用 python 在 Jupyter 实验室中找不到文件错误
【发布时间】:2020-10-07 02:59:18
【问题描述】:

我使用在线jupyterlab which can be accessed through this link below if not then use the second link

This is the second link

所以问题是我已将 .csv 格式文件上传到实验室,但当我尝试使用此代码加载它时

import pandas as pd
import matplotlib.pyplot as plt
from collections import Counter
import seaborn as sns

df = pd.read_csv ('demo/big.csv')

print(df)

它给了我以下错误

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-2-56c1e19c9da6> in <module>
  1 #Task 1
----> 2 df = pd.read_csv ('demo/big.csv')
  3 
  4 print(df)

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/io/parsers.py in 
parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, 
prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, 
skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, 
verbose, 
skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, 
iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, 
doublequote, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, 
warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
700                     skip_blank_lines=skip_blank_lines)
701 
--> 702         return _read(filepath_or_buffer, kwds)
703 
704     parser_f.__name__ = name

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/io/parsers.py in 
_read(filepath_or_buffer, kwds)
427 
428     # Create the parser.
--> 429     parser = TextFileReader(filepath_or_buffer, **kwds)
430 
431     if chunksize or iterator:

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/io/parsers.py in __init__(self, 
f, engine, **kwds)
893             self.options['has_index_names'] = kwds['has_index_names']
894 
--> 895         self._make_engine(self.engine)
896 
897     def close(self):

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/io/parsers.py in 
_make_engine(self, engine)
1120     def _make_engine(self, engine='c'):
1121         if engine == 'c':
-> 1122             self._engine = CParserWrapper(self.f, **self.options)
1123         else:
1124             if engine == 'python':

/srv/conda/envs/notebook/lib/python3.7/site-packages/pandas/io/parsers.py in __init__(self, 
src, **kwds)
1851         kwds['usecols'] = self.usecols
1852 
-> 1853         self._reader = parsers.TextReader(src, **kwds)
1854         self.unnamed_cols = self._reader.unnamed_cols
1855 

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: [Errno 2] File b'demo/big.csv' does not exist: b'demo/big.csv'

请帮我看看我给的路径不正确还是这里有什么问题?

【问题讨论】:

    标签: python python-3.x jupyter-notebook jupyter-lab


    【解决方案1】:

    您应该检查并确保您的笔记本与您尝试导入的文件位于同一目录中。因此,如果笔记本位于桌面上名为“Notebooks”的文件夹中,则将数据放在该文件夹中。然后,确保

    df = pd.read_csv ('demo/big.csv')
    

    您的代码部分只有文件名和 .csv 结尾。如果文件被命名为 big.csv,那么它应该是

    df = pd.read_csv ('big.csv') 
    

    这些是您收到该错误的主要原因。

    【讨论】:

    • 我正在使用在线 jupyter 实验室文件不在我的本地机器中我将其上传到所有文件所在的同一目录,即演示目录,但我仍然收到错误不知道为什么
    • 您可以将它们下载到本地计算机还是从 github 存储库中提取它们?
    • 在我的本地机器上没有,但我把它上传到了我在 jupyter 实验室工作的网站jupyter.org/try 你能检查那个网站并尝试将文件上传到它吗?它将为您解决问题,然后您可以告诉我
    猜你喜欢
    • 2018-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-04
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 2020-11-22
    相关资源
    最近更新 更多