为什么Jupyter无法读取.csv文件? [英] Why Jupyter can't read the .csv file?

查看:912
本文介绍了为什么Jupyter无法读取.csv文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jupyter笔记本中使用python 3.问题是它无法读取csv文件.读取我使用过的csv文件的命令是:

I'm using python 3 in jupyter notebook. The problem is that it can't read the csv file. The command to read the csv file i have used is:

  import pandas as pd

df = pd.read_csv("py.csv")
df

我也尝试了许多其他方法,但是每次它说时,虽然我PC中的csv文件都找不到该文件.

I have tried a lot of other ways too, but every time it says that , file is not found although the csv file in my pc.

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-4-cc06427474dd> in <module>()
      1 import pandas as pd
      2 
----> 3 df = pd.read_csv("py.csv")
      4 df

~/anaconda/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, 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, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision)
    653                     skip_blank_lines=skip_blank_lines)
    654 
--> 655         return _read(filepath_or_buffer, kwds)
    656 
    657     parser_f.__name__ = name

~/anaconda/lib/python3.6/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
    403 
    404     # Create the parser.
--> 405     parser = TextFileReader(filepath_or_buffer, **kwds)
    406 
    407     if chunksize or iterator:

~/anaconda/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, f, engine, **kwds)
    762             self.options['has_index_names'] = kwds['has_index_names']
    763 
--> 764         self._make_engine(self.engine)
    765 
    766     def close(self):

~/anaconda/lib/python3.6/site-packages/pandas/io/parsers.py in _make_engine(self, engine)
    983     def _make_engine(self, engine='c'):
    984         if engine == 'c':
--> 985             self._engine = CParserWrapper(self.f, **self.options)
    986         else:
    987             if engine == 'python':

~/anaconda/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
   1603         kwds['allow_leading_cols'] = self.index_col is not False
   1604 
-> 1605         self._reader = parsers.TextReader(src, **kwds)
   1606 
   1607         # XXX

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__ (pandas/_libs/parsers.c:4209)()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source (pandas/_libs/parsers.c:8873)()

FileNotFoundError: File b'py.csv' does not exist

推荐答案

使用类似

pd.read_csv('C:\Users\user\Desktop\Workbook1.csv')

当前您没有提到文件的路径,因此它正在当前不存在该文件的工作目录中查找.

Currently you are not mentioning the path to the file so it is looking in the current working directory where the file is not present.

可以将整个路径放入文件中,也可以将文件放入工作目录中 希望对您有帮助!

Either put the whole path or put your file in the working directory Hope it helps!

这篇关于为什么Jupyter无法读取.csv文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆