为什么无法将csv文件导入jupyternotebook?

时间:2020-02-29 18:44:30

标签: python pandas csv jupyter-notebook

因此,我尝试在jupyter笔记本中导入一个csv文件,但出现错误。 我写的代码是:

import pandas as pd
df = pd.read_csv('all_stocks_5yr.csv')
df.head()

但是我得到了错误:

 FileNotFoundError                         Traceback (most recent call last)
ipython-input-11-a98d6fa5abb5> in <module>
          2 
          3 
    ----> 4 df = pd.read_csv('all_stocks_5yr.csv')
          5 df.head()

    C:\ProgramData\Anaconda3\lib\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, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
        683         )
        684 
    --> 685         return _read(filepath_or_buffer, kwds)
        686 
        687     parser_f.__name__ = name

    C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
        455 
        456     # Create the parser.
    --> 457     parser = TextFileReader(fp_or_buf, **kwds)
        458 
        459     if chunksize or iterator:

    C:\ProgramData\Anaconda3\lib\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):

    C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
       1133     def _make_engine(self, engine="c"):
       1134         if engine == "c":
    -> 1135             self._engine = CParserWrapper(self.f, **self.options)
       1136         else:
       1137             if engine == "python":

    C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py in __init__(self, src, **kwds)
       1915         kwds["usecols"] = self.usecols
       1916 
    -> 1917         self._reader = parsers.TextReader(src, **kwds)
       1918         self.unnamed_cols = self._reader.unnamed_cols
       1919 

    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'all_stocks_5yr.csv' does not exist: b'all_stocks_5yr.csv'

这是文件的图片,: enter image description here

我尝试过使用其他csv文件,如果我通过转到属性,然后使用位置并使用它来说出确切位置,那么我会收到错误消息:OSError: Initializing from file failed

0 个答案:

没有答案