如何解决Jupyter Notebook中的数据集读取错误?

时间:2019-04-04 00:35:47

标签: python pandas

我正在尝试修复错误,该如何使我的数据集能够被jupyter Notebook读取,但始终显示一些错误。与长消息框。此外,同样,我尝试查看jupyter笔记本是否存在任何问题,但是当我尝试读取少量数据时,它很容易读取。以下我已告知我所有信息,请帮助。     谢谢

df = pd.read_csv ("C:/Users/patel/Desktop/tap.csv")
print (df.head())

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-13-0901e21e4c23> in <module>
----> 1 df = pd.read_csv ("C:/Users/patel/Desktop/tap.csv", usecols = ["Source.name, data, hometeam, awayteam, fthg, ftag, ftr, htr"])
      2 print (df.head())

c:\users\patel\appdata\local\programs\python\python36-32\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, 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

c:\users\patel\appdata\local\programs\python\python36-32\lib\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:

c:\users\patel\appdata\local\programs\python\python36-32\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:\users\patel\appdata\local\programs\python\python36-32\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
        def _make_engine(self, engine='c'):
          if engine == 'c':
->             self._engine = CParserWrapper(self.f, **self.options)
           else:
               if engine == 'python':

c:\users\patel\appdata\local\programs\python\python36-32\lib\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/patel/Desktop/tap.csv' does not exist: b'C:/Users/patel/Desktop/tap.csv'


This is my trail for a small dataset which shows the path and all is okay. but I don't know what's wrong?



df = pd.read_csv("C:/Users/patel/Desktop/season-0809_csv.csv", header = 0)
print (df.head())



         Date    HomeTeam    AwayTeam  FTHG  FTAG FTR  HTHG  HTAG HTR  HS  \
0  2008-08-30     Espanol  Valladolid     1     0   H     0     0   D  10   
1  2008-08-30    Valencia    Mallorca     3     0   H     2     0   H  17   
2  2008-08-31  Ath Bilbao     Almeria     1     3   A     0     2   A  10   
3  2008-08-31  Ath Madrid      Malaga     4     0   H     3     0   H  25   
4  2008-08-31       Betis  Recreativo     0     1   A     0     1   A   8   

   ...  HST  AST  HF  AF  HC  AC  HY  AY  HR  AR  
0  ...    2    1  18  17   1   9   3   5   0   0  
1  ...    6    2  17  14   5   6   4   0   0   0  
2  ...    4    5  35  20   2   6   2   4   0   0  
3  ...    9    2  16  13  11   7   1   2   0   0  
4  ...    2    6  17  18   2   2   3   1   0   0  

[5 rows x 21 columns]

1 个答案:

答案 0 :(得分:0)

该错误表明找不到该文件:

  

FileNotFoundError:[错误2]文件b'C:/Users/patel/Desktop/tap.csv'不存在:b'C:/Users/patel/Desktop/tap.csv'

因此,如果您使用的是Windows,请确保按以下方式指定文件的路径:

CSV_FILE = "C:\\Users\\patel\\Desktop\\tap.csv"
df = pd.read_csv(CSV_FILE)