Error message我正在尝试将CSV文件上传到Jupyter笔记本上,并且我已经尝试使用这篇文章中的解决方案:
Why do I get a SyntaxError for a Unicode escape in my file path?
还有其他一些文章也提出了同样的建议。
当我尝试第一个建议时,我得到了这个错误:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-38-11b40256508f> in <module>
----> 1 df = pd.read_csv(r'C:\Users\Naveed\Desktop\RateStats.csv')
2 df.head()
~/conda/lib/python3.6/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
~/conda/lib/python3.6/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:
~/conda/lib/python3.6/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):
~/conda/lib/python3.6/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':
~/conda/lib/python3.6/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'C:\\Users\\Naveed\\Desktop\\RateStats.csv' does not exist: b'C:\\Users\\Naveed\\Desktop\\RateStats.csv'
然而,它仍然不起作用。我不确定我通过labs.cognitiveclass.ai使用Jupyter的事实是否与此有关,但我不认为这是问题所在。我在安装在我电脑上的Jupyter上试了一下,仍然无法上传CSV。
任何帮助都是非常感谢的。谢谢!
我希望至少能够输出前几行数据,而不是错误消息。
发布于 2019-04-12 11:41:08
您需要尝试以下操作:
df = pd.read_csv('C:\\Users\\Naveed\\Desktop\\RateStats.csv')
或
df = pd.read_csv('C:/Users/Naveed/Desktop/RateStats.csv')
问题是因为当您尝试使用
'C:\Users
\U
是unicode转义字符。
此外,如果是文件未找到错误,则需要确保RateStats
文件存在于给定的路径中。
发布于 2019-04-12 11:37:23
这将为您提供输出
df = pd.read_csv('C:\Users\Naveed\Desktop\RateStats.csv').head()
https://stackoverflow.com/questions/55644094
复制相似问题