【问题标题】:Csv file not uploading on Jupyter getting error未在 Jupyter 上上传的 CSV 文件出现错误
【发布时间】:2021-08-04 12:31:38
【问题描述】:

是否需要激活“Ms excel”才能在 jupyter 笔记本上上传 csv 文件。 上传 csv 文件时出现以下错误。所有的阵型我都试过了。

OSError                                   Traceback (most recent call last)
<ipython-input-3-dd35d6434e78> in <module>
----> 1 knn=pd.read_csv('‪C:\\Users\\cwc\\Downloads\\KNN_Data.csv')

~\anaconda3\lib\site-packages\pandas\io\parsers.py in read_csv(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, storage_options)
    608     kwds.update(kwds_defaults)
    609 
--> 610     return _read(filepath_or_buffer, kwds)
    611 
    612 

~\anaconda3\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
    460 
    461     # Create the parser.
--> 462     parser = TextFileReader(filepath_or_buffer, **kwds)
    463 
    464     if chunksize or iterator:

~\anaconda3\lib\site-packages\pandas\io\parsers.py in __init__(self, f, engine, **kwds)
    817             self.options["has_index_names"] = kwds["has_index_names"]
    818 
--> 819         self._engine = self._make_engine(self.engine)
    820 
    821     def close(self):

~\anaconda3\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
   1048             )
   1049         # error: Too many arguments for "ParserBase"
-> 1050         return mapping[engine](self.f, **self.options)  # type: ignore[call-arg]
   1051 
   1052     def _failover_to_python(self):

~\anaconda3\lib\site-packages\pandas\io\parsers.py in __init__(self, src, **kwds)
   1865 
   1866         # open handles
-> 1867         self._open_handles(src, kwds)
   1868         assert self.handles is not None
   1869         for key in ("storage_options", "encoding", "memory_map", "compression"):

~\anaconda3\lib\site-packages\pandas\io\parsers.py in _open_handles(self, src, kwds)
   1360         Let the readers open IOHanldes after they are done with their potential raises.
   1361         """
-> 1362         self.handles = get_handle(
   1363             src,
   1364             "r",

~\anaconda3\lib\site-packages\pandas\io\common.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    640                 errors = "replace"
    641             # Encoding
--> 642             handle = open(
    643                 handle,
    644                 ioargs.mode,

OSError: [Errno 22] Invalid argument: '\u202aC:\\Users\\cwc\\Downloads\\KNN_Data.csv'

【问题讨论】:

    标签: python python-3.x pandas csv


    【解决方案1】:

    在 C: 之前有一个不可见的空格。当我在简单引号之间复制/粘贴您的完整路径时,它会出现。重新输入您的修复路径。

    >>> '‪C:\\Users\\cwc\\Downloads\\KNN_Data.csv'
    '\u202aC:\\Users\\cwc\\Downloads\\KNN_Data.csv'
    

    复制/粘贴:

    r'C:\Users\cwc\Downloads\KNN_Data.csv'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-02
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 2012-05-23
      • 1970-01-01
      • 2015-05-31
      • 1970-01-01
      相关资源
      最近更新 更多