繁体   English   中英

如何在jupyter笔记本中修复数据集读取错误?

[英]how can fix the dataset read error in jupyter notebook?

我试图修复错误,我怎么能让我的数据集能够由jupyter笔记本读取,但它总是显示一些错误。 带有长消息框。 此外,我试图看看我的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]

错误表示找不到该文件:

FileNotFoundError:[Errno 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM